-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathConnected_Nodes.cpp
More file actions
52 lines (43 loc) · 802 Bytes
/
Connected_Nodes.cpp
File metadata and controls
52 lines (43 loc) · 802 Bytes
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
#include <bits/stdc++.h>
using namespace std;
const int N = 1e3 + 5;
vector<int> arr[N];
int main()
{
int n, e;
cin >> n >> e;
while (e--)
{
int a, b;
cin >> a >> b;
arr[a].push_back(b);
arr[b].push_back(a);
}
int q;
cin >> q;
while (q--)
{
int x;
cin >> x;
vector<int> v;
int sz = arr[x].size();
for (int i = 0; i < sz; i++)
{
v.push_back(arr[x][i]);
}
sort(v.begin(), v.end(), greater<int>());
if (v.empty())
{
cout << -1 << endl;
}
else
{
for (int child : v)
{
cout << child << " ";
}
cout << endl;
}
}
return 0;
}