-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconcom2.cpp
79 lines (66 loc) · 1.22 KB
/
concom2.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
79
/*
ID:kevin_s1
PROG:concom
LANG:C++
*/
#include <iostream>
#include <cstdio>
#include <string>
#include <cstring>
#include <vector>
#include <map>
#include <set>
#include <algorithm>
#include <cstdlib>
#include <list>
#include <cmath>
using namespace std;
#define MAXN 110
//gobal variable====
int N;
int owner[MAXN][MAXN];
int visited[MAXN];
int controls[MAXN];
int MAXINDEX;
int hash[MAXN];
//==================
//function==========
void DFS(int i){
visited[i] = 1;
for(int j = 1; j <= MAXINDEX; j++){
controls[j] += owner[i][j];
}
for(int j = 1; j <= MAXINDEX; j++){
if(controls[j] > 50 && !visited[j]){
DFS(j);
}
}
return;
}
//==================
int main(){
freopen("concom.in","r",stdin);
freopen("concom.out","w",stdout);
cin>>N;
int A, B, share;
memset(hash, 0, sizeof(hash));
MAXINDEX = 0;
for(int i = 1; i <= N; i++){
cin>>A>>B>>share;
owner[A][B] = share;
MAXINDEX = max(MAXINDEX, max(A, B));
hash[A] = 1;
hash[B] = 1;
}
for(int i = 1; i <= MAXINDEX; i++){
memset(controls, 0, sizeof(controls));
memset(visited, 0, sizeof(visited));
DFS(i);
for(int j = 1; j <= MAXINDEX; j++){
if(i != j && controls[j] > 50 && hash[i] && hash[j]){
cout<<i<<" "<<j<<endl;
}
}
}
return 0;
}