Advertisement
hugol

Question 1 - Skynet Finale - Level 1 - Training

Jun 19th, 2014
217
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.01 KB | None | 0 0
  1. #include <cstdio>
  2. #include <cstdlib>
  3.  
  4. #include <vector>
  5.  
  6. struct Node
  7. {
  8.     Node(bool gateway = false)
  9.     {
  10.         Node::gateway = gateway;
  11.     }
  12.     bool gateway;
  13.     std::vector<int> paths;
  14. };
  15.  
  16. int main()
  17. {
  18.  
  19.     unsigned int nodeCount, linkCount, gatewayCount;
  20.     scanf("%u %u %u", &nodeCount, &linkCount, &gatewayCount);
  21.     Node *nodes = new Node[nodeCount];
  22.  
  23.     // wczytwanie linkow
  24.     for(unsigned int i = 0; i < linkCount; ++i)
  25.     {
  26.         unsigned int a, b;
  27.         scanf("%u %u", &a, &b);
  28.         nodes[a].paths.push_back(b);
  29.         nodes[b].paths.push_back(a);
  30.     }
  31.     // wczytywanie gateways
  32.     for(unsigned int i = 0; i < gatewayCount; ++i)
  33.     {
  34.         unsigned int a;
  35.         scanf("%u", &a);
  36.         nodes[a].gateway = true;
  37.     }
  38.  
  39.     while (1)
  40.     {
  41.         unsigned int a, b;
  42.         scanf("%u", &a);
  43.         // gdyby nie bylo sasiada gateway
  44.         b = nodes[a].paths[0];
  45.         for (unsigned int i = 0; i < nodes[a].paths.size(); ++i)
  46.         {
  47.             if (nodes[nodes[a].paths[i]].gateway)
  48.             {
  49.                 b = nodes[a].paths[i];
  50.                 break;
  51.             }
  52.         }
  53.         printf("%u %u\n", a, b);
  54.     }
  55.  
  56.     return 0;
  57. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement