Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <cstdio>
- #include <cstdlib>
- #include <vector>
- struct Node
- {
- Node(bool gateway = false)
- {
- Node::gateway = gateway;
- }
- bool gateway;
- std::vector<int> paths;
- };
- int main()
- {
- unsigned int nodeCount, linkCount, gatewayCount;
- scanf("%u %u %u", &nodeCount, &linkCount, &gatewayCount);
- Node *nodes = new Node[nodeCount];
- // wczytwanie linkow
- for(unsigned int i = 0; i < linkCount; ++i)
- {
- unsigned int a, b;
- scanf("%u %u", &a, &b);
- nodes[a].paths.push_back(b);
- nodes[b].paths.push_back(a);
- }
- // wczytywanie gateways
- for(unsigned int i = 0; i < gatewayCount; ++i)
- {
- unsigned int a;
- scanf("%u", &a);
- nodes[a].gateway = true;
- }
- while (1)
- {
- unsigned int a, b;
- scanf("%u", &a);
- // gdyby nie bylo sasiada gateway
- b = nodes[a].paths[0];
- for (unsigned int i = 0; i < nodes[a].paths.size(); ++i)
- {
- if (nodes[nodes[a].paths[i]].gateway)
- {
- b = nodes[a].paths[i];
- break;
- }
- }
- printf("%u %u\n", a, b);
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement