manudude03

Skynet: the Virus (js)

Aug 22nd, 2015
147
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /**
  2.  * Auto-generated code below aims at helping you parse
  3.  * the standard input according to the problem statement.
  4.  **/
  5.  
  6. var inputs = readline().split(' ');
  7. var N = parseInt(inputs[0]); // the total number of nodes in the level, including the gateways
  8. var L = parseInt(inputs[1]); // the number of links
  9. var E = parseInt(inputs[2]); // the number of exit gateways
  10. var links = [];
  11. var gates = [];
  12. for (var i = 0; i < L; i++) {
  13.     var inputs = readline().split(' ');
  14.     var N1 = parseInt(inputs[0]); // N1 and N2 defines a link between these nodes
  15.     var N2 = parseInt(inputs[1]);
  16.     links.push([N1, N2]);
  17. }
  18. for (var i = 0; i < E; i++) {
  19.     var EI = parseInt(readline()); // the index of a gateway node
  20.     printErr(EI);
  21.     gates.push(EI);
  22. }
  23.  
  24. // game loop
  25. while (true) {
  26.     var SI = parseInt(readline()); // The index of the node on which the Skynet agent is positioned this turn
  27.     // Write an action using print()
  28.     // To debug: printErr('Debug messages...');
  29.     var p=false;
  30.     for (var i=0; i<links.length; i++)
  31.     {
  32.         for (var j=0; j<gates.length; j++)
  33.         {
  34.             if ((links[i][0]==SI && links[i][1]==gates[j])||(links[i][0]==gates[j] && links[i][1]==SI))
  35.             {
  36.                 print(links[i][0]+" "+links[i][1]);
  37.                 links.splice(i,1);
  38.                 p=true;
  39.             }
  40.         }
  41.     }
  42.     if (!p)
  43.     {
  44.         for (var i=0; i<links.length; i++)
  45.         {
  46.             if (!p&&(links[i][0]==SI || links[i][1]==SI))
  47.             {
  48.                 print(links[i][0]+" "+links[i][1]);
  49.                 links.splice(i,1);
  50.                 p=true;
  51.             }
  52.         }
  53.     }
  54. }
Advertisement
Add Comment
Please, Sign In to add comment