-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathalg_2.cpp
More file actions
54 lines (43 loc) · 1.02 KB
/
alg_2.cpp
File metadata and controls
54 lines (43 loc) · 1.02 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
#include <iostream>
#include <vector>
#include <list>
using namespace std;
typedef struct{
int ind;
int indicated_count;
}elem;
vector<elem> vec (100000);
vector<int> not_indicateds;
void group(int n, int begin, int end){
if(end > begin){
vec[not_indicateds[begin]].indicated_count--;
vec[vec[not_indicateds[begin]].ind].indicated_count--;
if(vec[vec[not_indicateds[begin]].ind].indicated_count <= 0){
not_indicateds.push_back(vec[not_indicateds[begin]].ind);
}
group(n, begin+1, not_indicateds.size());
}
}
int main(){
int n, indication, indicator;
cin >> n;
for(int i=0;i<=n;i++){
vec[i].indicated_count=0;
}
for(int i=0;i<n;i++){
cin >> indicator >> indication;
vec[indicator].ind = indication;
vec[indication].indicated_count++;
}
for(int i=1;i<=n;i++){
if(vec[i].indicated_count == 0){
not_indicateds.push_back(i);
}
}
group(n, 0, not_indicateds.size());
for(int i=1;i<=n;i++){
if(vec[i].indicated_count > 0){
cout << i << ' ';
}
}
}