-
Notifications
You must be signed in to change notification settings - Fork 0
/
11749.cpp
98 lines (92 loc) · 1.37 KB
/
11749.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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
/*
11749 - Poor Trade Advisor
*/
#include<bits/stdc++.h>
using namespace std;
int mat[505][505];
int vis[505];
int max_pda,n,m;
set<int>connected;
void dfs(int node)
{
for(int i=1; i<=n; i++)
{
if(mat[node][i]==max_pda && vis[i]==0)
{
vis[node]=vis[i]=1;
connected.insert(node);
connected.insert(i);
dfs(i);
}
}
}
void reset_mat()
{
for(int i=0; i<505; i++)
{
for(int j=0; j<505; j++)
{
mat[i][j]=INT_MIN;
}
}
}
int main()
{
int x,y,c;
while(cin>>n>>m)
{
if(n==0 && m==0)break;
max_pda=INT_MIN;
reset_mat();
for(int i=0; i<m; i++)
{
cin>>x>>y>>c;
if(mat[x][y]<c)
{
mat[x][y]=mat[y][x]=c;
}
max_pda=max(max_pda,c);
}
int max_area=0;
memset(vis,0,sizeof(vis));
for(int i=1; i<=n; i++)
{
if(vis[i]==0)
{
connected.clear();
dfs(i);
max_area=max(max_area,(int)connected.size());
}
}
cout<<max_area<<endl;
}
return 0;
}
/*
Sample Input
4 5
1 2 100
1 3 100
1 4 1
2 3 100
3 4 1
9 14
1 2 9
6 9 8
2 4 9
2 3 9
4 5 1
4 3 9
5 9 2
9 8 9
7 8 9
7 9 5
6 7 9
5 6 4
5 8 7
7 5 9
0 0
Sample Output
3
5
*/