#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
const ll maxN = (1e5*5)+10;
ll n, m;
vector<pair<ll, ll>> adj[maxN];
vector<pair<ll, ll>> adjFast[maxN];
ll findVal(ll v, ll v1){
ll l = 0, h = adjFast[v1].size()-1;
while(l<h){
ll mid = l+((h-l)/2);
if(adjFast[v1][mid].first==v)return adjFast[v1][mid].second;
else if(adjFast[v1][mid].first<v)l=mid+1;
else h=mid-1;
}
return -1;
}
int main()
{
ios_base::sync_with_stdio(0);cin.tie(nullptr);
cin>>n>>m;
for(ll i = 0; i < m; i++){
ll a, b, c;
cin>>a>>b>>c;
adj[a].push_back({b, c});
adj[b].push_back({a, c});
adjFast[a].push_back({b, c});
adjFast[b].push_back({a, c});
}
for(ll i = 1; i <= n; i++)sort(adjFast[i].begin(), adjFast[i].end());
ll ans=0;
for(ll i = 1; i <= n; i++){
ll temp=0;
for(auto x : adj[i]){
temp+=x.second;
}
for(ll x = 0; x < (ll)(adj[i].size())-1; x++){
ll val=-1;
ll v1=adj[i][x].first, v2=adj[i][x+1].first;
val = findVal(v2, v1);
if(val==-1)continue;
temp=max(temp, adj[i][x].second+adj[i][x+1].second+val);
}
ans=max(ans, temp);
}
cout<<ans;
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
13 ms |
23756 KB |
Output is correct |
2 |
Correct |
13 ms |
23780 KB |
Output is correct |
3 |
Correct |
14 ms |
23756 KB |
Output is correct |
4 |
Correct |
13 ms |
23756 KB |
Output is correct |
5 |
Correct |
12 ms |
23800 KB |
Output is correct |
6 |
Correct |
18 ms |
25592 KB |
Output is correct |
7 |
Correct |
13 ms |
23756 KB |
Output is correct |
8 |
Correct |
14 ms |
23892 KB |
Output is correct |
9 |
Correct |
12 ms |
23756 KB |
Output is correct |
10 |
Correct |
13 ms |
23804 KB |
Output is correct |
11 |
Correct |
12 ms |
23756 KB |
Output is correct |
12 |
Correct |
12 ms |
23756 KB |
Output is correct |
13 |
Correct |
12 ms |
23788 KB |
Output is correct |
14 |
Correct |
12 ms |
23764 KB |
Output is correct |
15 |
Correct |
12 ms |
23800 KB |
Output is correct |
16 |
Correct |
14 ms |
23672 KB |
Output is correct |
17 |
Correct |
13 ms |
23756 KB |
Output is correct |
18 |
Correct |
14 ms |
23804 KB |
Output is correct |
19 |
Correct |
13 ms |
23944 KB |
Output is correct |
20 |
Correct |
12 ms |
23804 KB |
Output is correct |
21 |
Correct |
12 ms |
23736 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
13 ms |
23756 KB |
Output is correct |
2 |
Correct |
13 ms |
23780 KB |
Output is correct |
3 |
Correct |
14 ms |
23756 KB |
Output is correct |
4 |
Correct |
13 ms |
23756 KB |
Output is correct |
5 |
Correct |
12 ms |
23800 KB |
Output is correct |
6 |
Correct |
18 ms |
25592 KB |
Output is correct |
7 |
Correct |
13 ms |
23756 KB |
Output is correct |
8 |
Correct |
14 ms |
23892 KB |
Output is correct |
9 |
Correct |
12 ms |
23756 KB |
Output is correct |
10 |
Correct |
13 ms |
23804 KB |
Output is correct |
11 |
Correct |
12 ms |
23756 KB |
Output is correct |
12 |
Correct |
12 ms |
23756 KB |
Output is correct |
13 |
Correct |
12 ms |
23788 KB |
Output is correct |
14 |
Correct |
12 ms |
23764 KB |
Output is correct |
15 |
Correct |
12 ms |
23800 KB |
Output is correct |
16 |
Correct |
14 ms |
23672 KB |
Output is correct |
17 |
Correct |
13 ms |
23756 KB |
Output is correct |
18 |
Correct |
14 ms |
23804 KB |
Output is correct |
19 |
Correct |
13 ms |
23944 KB |
Output is correct |
20 |
Correct |
12 ms |
23804 KB |
Output is correct |
21 |
Correct |
12 ms |
23736 KB |
Output is correct |
22 |
Correct |
413 ms |
75956 KB |
Output is correct |
23 |
Correct |
214 ms |
64920 KB |
Output is correct |
24 |
Correct |
26 ms |
26084 KB |
Output is correct |
25 |
Correct |
16 ms |
24388 KB |
Output is correct |
26 |
Correct |
16 ms |
24448 KB |
Output is correct |
27 |
Correct |
13 ms |
24068 KB |
Output is correct |
28 |
Correct |
104 ms |
44740 KB |
Output is correct |
29 |
Correct |
58 ms |
32100 KB |
Output is correct |
30 |
Correct |
88 ms |
34600 KB |
Output is correct |
31 |
Correct |
13 ms |
23808 KB |
Output is correct |
32 |
Correct |
12 ms |
23756 KB |
Output is correct |
33 |
Correct |
211 ms |
72304 KB |
Output is correct |
34 |
Correct |
158 ms |
67016 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
142 ms |
42460 KB |
Output is correct |
2 |
Correct |
371 ms |
53996 KB |
Output is correct |
3 |
Correct |
123 ms |
33988 KB |
Output is correct |
4 |
Correct |
222 ms |
46704 KB |
Output is correct |
5 |
Correct |
417 ms |
59248 KB |
Output is correct |
6 |
Correct |
55 ms |
33092 KB |
Output is correct |
7 |
Correct |
119 ms |
51704 KB |
Output is correct |
8 |
Correct |
128 ms |
56368 KB |
Output is correct |
9 |
Correct |
19 ms |
23884 KB |
Output is correct |
10 |
Correct |
59 ms |
33136 KB |
Output is correct |
11 |
Correct |
126 ms |
54420 KB |
Output is correct |
12 |
Correct |
87 ms |
42436 KB |
Output is correct |
13 |
Correct |
13 ms |
23780 KB |
Output is correct |
14 |
Correct |
86 ms |
33620 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
142 ms |
42460 KB |
Output is correct |
2 |
Correct |
371 ms |
53996 KB |
Output is correct |
3 |
Correct |
123 ms |
33988 KB |
Output is correct |
4 |
Correct |
222 ms |
46704 KB |
Output is correct |
5 |
Correct |
417 ms |
59248 KB |
Output is correct |
6 |
Correct |
55 ms |
33092 KB |
Output is correct |
7 |
Correct |
119 ms |
51704 KB |
Output is correct |
8 |
Correct |
128 ms |
56368 KB |
Output is correct |
9 |
Correct |
19 ms |
23884 KB |
Output is correct |
10 |
Correct |
59 ms |
33136 KB |
Output is correct |
11 |
Correct |
126 ms |
54420 KB |
Output is correct |
12 |
Correct |
87 ms |
42436 KB |
Output is correct |
13 |
Correct |
13 ms |
23780 KB |
Output is correct |
14 |
Correct |
86 ms |
33620 KB |
Output is correct |
15 |
Correct |
13 ms |
23756 KB |
Output is correct |
16 |
Correct |
13 ms |
23780 KB |
Output is correct |
17 |
Correct |
14 ms |
23756 KB |
Output is correct |
18 |
Correct |
13 ms |
23756 KB |
Output is correct |
19 |
Correct |
12 ms |
23800 KB |
Output is correct |
20 |
Correct |
18 ms |
25592 KB |
Output is correct |
21 |
Correct |
13 ms |
23756 KB |
Output is correct |
22 |
Correct |
14 ms |
23892 KB |
Output is correct |
23 |
Correct |
12 ms |
23756 KB |
Output is correct |
24 |
Correct |
13 ms |
23804 KB |
Output is correct |
25 |
Correct |
12 ms |
23756 KB |
Output is correct |
26 |
Correct |
12 ms |
23756 KB |
Output is correct |
27 |
Correct |
12 ms |
23788 KB |
Output is correct |
28 |
Correct |
12 ms |
23764 KB |
Output is correct |
29 |
Correct |
12 ms |
23800 KB |
Output is correct |
30 |
Correct |
14 ms |
23672 KB |
Output is correct |
31 |
Correct |
13 ms |
23756 KB |
Output is correct |
32 |
Correct |
14 ms |
23804 KB |
Output is correct |
33 |
Correct |
13 ms |
23944 KB |
Output is correct |
34 |
Correct |
12 ms |
23804 KB |
Output is correct |
35 |
Correct |
12 ms |
23736 KB |
Output is correct |
36 |
Correct |
413 ms |
75956 KB |
Output is correct |
37 |
Correct |
214 ms |
64920 KB |
Output is correct |
38 |
Correct |
26 ms |
26084 KB |
Output is correct |
39 |
Correct |
16 ms |
24388 KB |
Output is correct |
40 |
Correct |
16 ms |
24448 KB |
Output is correct |
41 |
Correct |
13 ms |
24068 KB |
Output is correct |
42 |
Correct |
104 ms |
44740 KB |
Output is correct |
43 |
Correct |
58 ms |
32100 KB |
Output is correct |
44 |
Correct |
88 ms |
34600 KB |
Output is correct |
45 |
Correct |
13 ms |
23808 KB |
Output is correct |
46 |
Correct |
12 ms |
23756 KB |
Output is correct |
47 |
Correct |
211 ms |
72304 KB |
Output is correct |
48 |
Correct |
158 ms |
67016 KB |
Output is correct |
49 |
Correct |
165 ms |
44512 KB |
Output is correct |
50 |
Correct |
135 ms |
43620 KB |
Output is correct |
51 |
Correct |
184 ms |
45248 KB |
Output is correct |
52 |
Correct |
205 ms |
48384 KB |
Output is correct |
53 |
Correct |
93 ms |
34988 KB |
Output is correct |
54 |
Correct |
170 ms |
61936 KB |
Output is correct |
55 |
Correct |
367 ms |
61140 KB |
Output is correct |
56 |
Correct |
235 ms |
48452 KB |
Output is correct |
57 |
Correct |
237 ms |
51660 KB |
Output is correct |
58 |
Correct |
149 ms |
38260 KB |
Output is correct |
59 |
Correct |
291 ms |
57140 KB |
Output is correct |
60 |
Correct |
213 ms |
52792 KB |
Output is correct |
61 |
Incorrect |
219 ms |
51060 KB |
Output isn't correct |