#include<bits/stdc++.h>
using namespace std;
const int mx=500009;
typedef long long ll;
map<pair<int,int>,ll>mp;
vector<pair<int,ll>>adj[mx];
int n,m;
ll ans;
int vis[mx];
void dfs(int node,int par){
vis[node]=2;
for(auto it:adj[node]){
if(it.first==par){continue;}
if(vis[it.first]==2&&mp.find({par,it.first})!=mp.end()){
ans=max(ans,1LL*(it.second+mp[{it.first,par}]+mp[{node,par}]));
}else if(vis[it.first]){
continue;
}else{
dfs(it.first,node);
}
}
vis[node]=1;
}
int main()
{
ios_base::sync_with_stdio(0);
cin.tie();
cin>>n>>m;
for(int i=0; i<m; i++)
{
int x,y,w;
cin>>x>>y>>w;
adj[x].push_back({y,w});
adj[y].push_back({x,w});
mp[{x,y}]=w;
mp[{y,x}]=w;
}
for(int i=1;i<=n;i++){
if(!vis[i]){
dfs(i,0);
}
ll tmp=0;
for(auto it:adj[i]){
tmp+=it.second;
}
ans=max(ans,tmp);
}
cout<<ans;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
8 ms |
11988 KB |
Output is correct |
2 |
Correct |
8 ms |
11988 KB |
Output is correct |
3 |
Correct |
8 ms |
12036 KB |
Output is correct |
4 |
Correct |
6 ms |
11988 KB |
Output is correct |
5 |
Correct |
6 ms |
11988 KB |
Output is correct |
6 |
Correct |
23 ms |
15424 KB |
Output is correct |
7 |
Correct |
6 ms |
11988 KB |
Output is correct |
8 |
Correct |
7 ms |
11988 KB |
Output is correct |
9 |
Correct |
6 ms |
11988 KB |
Output is correct |
10 |
Correct |
6 ms |
11988 KB |
Output is correct |
11 |
Correct |
10 ms |
12148 KB |
Output is correct |
12 |
Correct |
8 ms |
12116 KB |
Output is correct |
13 |
Correct |
7 ms |
12112 KB |
Output is correct |
14 |
Correct |
6 ms |
11988 KB |
Output is correct |
15 |
Correct |
9 ms |
12032 KB |
Output is correct |
16 |
Correct |
7 ms |
11988 KB |
Output is correct |
17 |
Correct |
8 ms |
11988 KB |
Output is correct |
18 |
Correct |
7 ms |
12172 KB |
Output is correct |
19 |
Correct |
8 ms |
12372 KB |
Output is correct |
20 |
Correct |
6 ms |
11988 KB |
Output is correct |
21 |
Correct |
6 ms |
11988 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
8 ms |
11988 KB |
Output is correct |
2 |
Correct |
8 ms |
11988 KB |
Output is correct |
3 |
Correct |
8 ms |
12036 KB |
Output is correct |
4 |
Correct |
6 ms |
11988 KB |
Output is correct |
5 |
Correct |
6 ms |
11988 KB |
Output is correct |
6 |
Correct |
23 ms |
15424 KB |
Output is correct |
7 |
Correct |
6 ms |
11988 KB |
Output is correct |
8 |
Correct |
7 ms |
11988 KB |
Output is correct |
9 |
Correct |
6 ms |
11988 KB |
Output is correct |
10 |
Correct |
6 ms |
11988 KB |
Output is correct |
11 |
Correct |
10 ms |
12148 KB |
Output is correct |
12 |
Correct |
8 ms |
12116 KB |
Output is correct |
13 |
Correct |
7 ms |
12112 KB |
Output is correct |
14 |
Correct |
6 ms |
11988 KB |
Output is correct |
15 |
Correct |
9 ms |
12032 KB |
Output is correct |
16 |
Correct |
7 ms |
11988 KB |
Output is correct |
17 |
Correct |
8 ms |
11988 KB |
Output is correct |
18 |
Correct |
7 ms |
12172 KB |
Output is correct |
19 |
Correct |
8 ms |
12372 KB |
Output is correct |
20 |
Correct |
6 ms |
11988 KB |
Output is correct |
21 |
Correct |
6 ms |
11988 KB |
Output is correct |
22 |
Correct |
1447 ms |
95804 KB |
Output is correct |
23 |
Correct |
630 ms |
90828 KB |
Output is correct |
24 |
Correct |
34 ms |
15564 KB |
Output is correct |
25 |
Correct |
15 ms |
13140 KB |
Output is correct |
26 |
Correct |
13 ms |
13140 KB |
Output is correct |
27 |
Correct |
10 ms |
12500 KB |
Output is correct |
28 |
Correct |
379 ms |
45384 KB |
Output is correct |
29 |
Correct |
215 ms |
25356 KB |
Output is correct |
30 |
Correct |
280 ms |
31708 KB |
Output is correct |
31 |
Correct |
6 ms |
12116 KB |
Output is correct |
32 |
Correct |
7 ms |
12116 KB |
Output is correct |
33 |
Correct |
514 ms |
93572 KB |
Output is correct |
34 |
Correct |
458 ms |
87184 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
298 ms |
43676 KB |
Output is correct |
2 |
Correct |
643 ms |
70612 KB |
Output is correct |
3 |
Correct |
197 ms |
31604 KB |
Output is correct |
4 |
Correct |
392 ms |
51292 KB |
Output is correct |
5 |
Correct |
950 ms |
80684 KB |
Output is correct |
6 |
Correct |
178 ms |
32892 KB |
Output is correct |
7 |
Correct |
222 ms |
71976 KB |
Output is correct |
8 |
Correct |
299 ms |
69280 KB |
Output is correct |
9 |
Correct |
11 ms |
13396 KB |
Output is correct |
10 |
Correct |
141 ms |
32992 KB |
Output is correct |
11 |
Correct |
278 ms |
69656 KB |
Output is correct |
12 |
Correct |
254 ms |
54044 KB |
Output is correct |
13 |
Correct |
7 ms |
12132 KB |
Output is correct |
14 |
Correct |
170 ms |
30156 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
298 ms |
43676 KB |
Output is correct |
2 |
Correct |
643 ms |
70612 KB |
Output is correct |
3 |
Correct |
197 ms |
31604 KB |
Output is correct |
4 |
Correct |
392 ms |
51292 KB |
Output is correct |
5 |
Correct |
950 ms |
80684 KB |
Output is correct |
6 |
Correct |
178 ms |
32892 KB |
Output is correct |
7 |
Correct |
222 ms |
71976 KB |
Output is correct |
8 |
Correct |
299 ms |
69280 KB |
Output is correct |
9 |
Correct |
11 ms |
13396 KB |
Output is correct |
10 |
Correct |
141 ms |
32992 KB |
Output is correct |
11 |
Correct |
278 ms |
69656 KB |
Output is correct |
12 |
Correct |
254 ms |
54044 KB |
Output is correct |
13 |
Correct |
7 ms |
12132 KB |
Output is correct |
14 |
Correct |
170 ms |
30156 KB |
Output is correct |
15 |
Correct |
8 ms |
11988 KB |
Output is correct |
16 |
Correct |
8 ms |
11988 KB |
Output is correct |
17 |
Correct |
8 ms |
12036 KB |
Output is correct |
18 |
Correct |
6 ms |
11988 KB |
Output is correct |
19 |
Correct |
6 ms |
11988 KB |
Output is correct |
20 |
Correct |
23 ms |
15424 KB |
Output is correct |
21 |
Correct |
6 ms |
11988 KB |
Output is correct |
22 |
Correct |
7 ms |
11988 KB |
Output is correct |
23 |
Correct |
6 ms |
11988 KB |
Output is correct |
24 |
Correct |
6 ms |
11988 KB |
Output is correct |
25 |
Correct |
10 ms |
12148 KB |
Output is correct |
26 |
Correct |
8 ms |
12116 KB |
Output is correct |
27 |
Correct |
7 ms |
12112 KB |
Output is correct |
28 |
Correct |
6 ms |
11988 KB |
Output is correct |
29 |
Correct |
9 ms |
12032 KB |
Output is correct |
30 |
Correct |
7 ms |
11988 KB |
Output is correct |
31 |
Correct |
8 ms |
11988 KB |
Output is correct |
32 |
Correct |
7 ms |
12172 KB |
Output is correct |
33 |
Correct |
8 ms |
12372 KB |
Output is correct |
34 |
Correct |
6 ms |
11988 KB |
Output is correct |
35 |
Correct |
6 ms |
11988 KB |
Output is correct |
36 |
Correct |
1447 ms |
95804 KB |
Output is correct |
37 |
Correct |
630 ms |
90828 KB |
Output is correct |
38 |
Correct |
34 ms |
15564 KB |
Output is correct |
39 |
Correct |
15 ms |
13140 KB |
Output is correct |
40 |
Correct |
13 ms |
13140 KB |
Output is correct |
41 |
Correct |
10 ms |
12500 KB |
Output is correct |
42 |
Correct |
379 ms |
45384 KB |
Output is correct |
43 |
Correct |
215 ms |
25356 KB |
Output is correct |
44 |
Correct |
280 ms |
31708 KB |
Output is correct |
45 |
Correct |
6 ms |
12116 KB |
Output is correct |
46 |
Correct |
7 ms |
12116 KB |
Output is correct |
47 |
Correct |
514 ms |
93572 KB |
Output is correct |
48 |
Correct |
458 ms |
87184 KB |
Output is correct |
49 |
Correct |
498 ms |
50572 KB |
Output is correct |
50 |
Correct |
411 ms |
48688 KB |
Output is correct |
51 |
Correct |
597 ms |
53388 KB |
Output is correct |
52 |
Correct |
799 ms |
63612 KB |
Output is correct |
53 |
Correct |
155 ms |
31544 KB |
Output is correct |
54 |
Correct |
729 ms |
69396 KB |
Output is correct |
55 |
Correct |
674 ms |
106184 KB |
Output is correct |
56 |
Correct |
392 ms |
74508 KB |
Output is correct |
57 |
Correct |
540 ms |
65940 KB |
Output is correct |
58 |
Correct |
302 ms |
40552 KB |
Output is correct |
59 |
Correct |
795 ms |
72460 KB |
Output is correct |
60 |
Correct |
796 ms |
65488 KB |
Output is correct |
61 |
Correct |
753 ms |
63172 KB |
Output is correct |