forked from ntalfer/codingame
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathskynet_le_final_niveau_1.cpp
78 lines (63 loc) · 1.55 KB
/
skynet_le_final_niveau_1.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
#include <iostream>
#include <string>
#include <vector>
#include <set>
using namespace std;
class Node
{
public:
Node()
{
is_gateway = false;
}
set<int> neighbors;
bool is_gateway;
};
int main()
{
// Read init information from standard input, if any
int n, l, e;
cin >> n >> l >> e;
vector<Node*> nodes;
for(int i=0; i<n; i++)
nodes.push_back(new Node());
int n1, n2;
for(int i=0; i<l; i++)
{
cin >> n1 >> n2;
nodes[n1]->neighbors.insert(n2);
nodes[n2]->neighbors.insert(n1);
}
int ei;
for(int i=0; i<e; i++)
{
cin >> ei;
nodes[ei]->is_gateway = true;
}
while (1) {
// Read information from standard input
int si;
cin >> si;
int sj = -1;
// if one neighbor of skynet is a gateway, break the link
Node* skynet = nodes[si];
for(set<int>::iterator it=skynet->neighbors.begin(); it!=skynet->neighbors.end(); ++it)
{
if(nodes[*it]->is_gateway)
{
sj = *it;
break;
}
}
// no skynet neighbor is a gateway, break the link
// with the first neighbor
if(sj == -1)
sj = *skynet->neighbors.begin();
// update links info
skynet->neighbors.erase(sj);
nodes[sj]->neighbors.erase(si);
// Write action to standard output
cout << si << " " << sj << endl;
}
return 0;
}