-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbard.cpp
More file actions
56 lines (51 loc) · 1.12 KB
/
bard.cpp
File metadata and controls
56 lines (51 loc) · 1.12 KB
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
#include <bits/stdc++.h>
#include <unordered_set>
using namespace std;
#define ar array
#define ll long long
void solve() {
int n,e;
cin>>n>>e;
int songs=0;
unordered_set<int> arr[n+1];
while(e--){
int k;
cin>>k;
unordered_set<int> new_s;
vector<int> villagers;
bool has_bard=false;
while(k--){
int x;
cin>>x;
villagers.push_back(x);
if(x==1){
has_bard=true;
songs++;
}else{
new_s.insert(arr[x].begin(),arr[x].end());
}
}
for(int x:villagers){
if(has_bard){
arr[x].insert(songs);
}else{
arr[x]=new_s;
}
}
}
for(int i=1;i<=n;i++){
if(arr[i].size()==songs){
cout<<i<<endl;
}
}
}
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
int tc = 1;
// cin >> tc;
for (int t = 1; t <= tc; t++) {
// cout << "Case #" << t << ": ";
solve();
}
}