-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patholliePS-347.cpp
60 lines (46 loc) · 976 Bytes
/
olliePS-347.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
#include <bits/stdc++.h>
using namespace std;
#define ll long long
void king(ll vertex , vector<ll> graph[] , ll count , set<ll>& st)
{
if (count == 2)
{
return;
}
for (ll node : graph[vertex])
{
st.insert(node);
king(node , graph , count + 1 , st);
}
}
int main()
{
ios::sync_with_stdio(false);
cin.tie(nullptr);
ll t;
cin >> t;
while (t--)
{
ll vertices;
cin >> vertices;
vector<ll> G[vertices + 1];
ll edges = (vertices * (vertices - 1)) / 2;
for (ll i = 0; i < edges; i++)
{
ll v1, v2;
cin >> v1 >> v2;
G[v1].push_back(v2);
}
for (ll j = 1; j <= vertices; j++)
{
set<ll> st;
king(j , G , 0 , st);
if(st.size() == vertices - 1)
{
cout << j << " ";
}
}
cout << endl;
}
return 0;
}