#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;
}
ans=max(ans, temp);
}
for(ll i = 1; i <= n; i++){
for(ll x = 0; x < (ll)(adj[i].size())-1; x++){
ll temp=0;
ll val=-1;
ll v1=adj[i][x].first, v2=adj[i][x+1].first;
val = findVal(v2, v1);
if(val==-1)continue;
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 |
23712 KB |
Output is correct |
3 |
Correct |
12 ms |
23796 KB |
Output is correct |
4 |
Correct |
13 ms |
23804 KB |
Output is correct |
5 |
Correct |
12 ms |
23796 KB |
Output is correct |
6 |
Correct |
19 ms |
25548 KB |
Output is correct |
7 |
Correct |
12 ms |
23756 KB |
Output is correct |
8 |
Correct |
12 ms |
23716 KB |
Output is correct |
9 |
Correct |
12 ms |
23800 KB |
Output is correct |
10 |
Correct |
12 ms |
23748 KB |
Output is correct |
11 |
Correct |
12 ms |
23756 KB |
Output is correct |
12 |
Correct |
14 ms |
23872 KB |
Output is correct |
13 |
Correct |
15 ms |
23756 KB |
Output is correct |
14 |
Correct |
12 ms |
23800 KB |
Output is correct |
15 |
Correct |
14 ms |
23756 KB |
Output is correct |
16 |
Correct |
14 ms |
23796 KB |
Output is correct |
17 |
Correct |
12 ms |
23796 KB |
Output is correct |
18 |
Correct |
12 ms |
23884 KB |
Output is correct |
19 |
Correct |
12 ms |
24012 KB |
Output is correct |
20 |
Correct |
11 ms |
23756 KB |
Output is correct |
21 |
Correct |
12 ms |
23700 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
13 ms |
23756 KB |
Output is correct |
2 |
Correct |
13 ms |
23712 KB |
Output is correct |
3 |
Correct |
12 ms |
23796 KB |
Output is correct |
4 |
Correct |
13 ms |
23804 KB |
Output is correct |
5 |
Correct |
12 ms |
23796 KB |
Output is correct |
6 |
Correct |
19 ms |
25548 KB |
Output is correct |
7 |
Correct |
12 ms |
23756 KB |
Output is correct |
8 |
Correct |
12 ms |
23716 KB |
Output is correct |
9 |
Correct |
12 ms |
23800 KB |
Output is correct |
10 |
Correct |
12 ms |
23748 KB |
Output is correct |
11 |
Correct |
12 ms |
23756 KB |
Output is correct |
12 |
Correct |
14 ms |
23872 KB |
Output is correct |
13 |
Correct |
15 ms |
23756 KB |
Output is correct |
14 |
Correct |
12 ms |
23800 KB |
Output is correct |
15 |
Correct |
14 ms |
23756 KB |
Output is correct |
16 |
Correct |
14 ms |
23796 KB |
Output is correct |
17 |
Correct |
12 ms |
23796 KB |
Output is correct |
18 |
Correct |
12 ms |
23884 KB |
Output is correct |
19 |
Correct |
12 ms |
24012 KB |
Output is correct |
20 |
Correct |
11 ms |
23756 KB |
Output is correct |
21 |
Correct |
12 ms |
23700 KB |
Output is correct |
22 |
Correct |
351 ms |
67636 KB |
Output is correct |
23 |
Correct |
217 ms |
56480 KB |
Output is correct |
24 |
Correct |
27 ms |
26000 KB |
Output is correct |
25 |
Correct |
18 ms |
24396 KB |
Output is correct |
26 |
Correct |
15 ms |
24396 KB |
Output is correct |
27 |
Correct |
15 ms |
24068 KB |
Output is correct |
28 |
Correct |
98 ms |
41468 KB |
Output is correct |
29 |
Correct |
52 ms |
31112 KB |
Output is correct |
30 |
Correct |
90 ms |
32752 KB |
Output is correct |
31 |
Correct |
13 ms |
23884 KB |
Output is correct |
32 |
Correct |
12 ms |
23808 KB |
Output is correct |
33 |
Correct |
187 ms |
64540 KB |
Output is correct |
34 |
Correct |
151 ms |
62064 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
129 ms |
42632 KB |
Output is correct |
2 |
Correct |
331 ms |
54300 KB |
Output is correct |
3 |
Correct |
89 ms |
33976 KB |
Output is correct |
4 |
Correct |
204 ms |
43972 KB |
Output is correct |
5 |
Correct |
380 ms |
54948 KB |
Output is correct |
6 |
Correct |
64 ms |
31940 KB |
Output is correct |
7 |
Correct |
115 ms |
48108 KB |
Output is correct |
8 |
Correct |
125 ms |
52156 KB |
Output is correct |
9 |
Correct |
15 ms |
23932 KB |
Output is correct |
10 |
Correct |
51 ms |
32024 KB |
Output is correct |
11 |
Correct |
136 ms |
51692 KB |
Output is correct |
12 |
Correct |
87 ms |
40012 KB |
Output is correct |
13 |
Correct |
12 ms |
23796 KB |
Output is correct |
14 |
Correct |
60 ms |
32632 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
129 ms |
42632 KB |
Output is correct |
2 |
Correct |
331 ms |
54300 KB |
Output is correct |
3 |
Correct |
89 ms |
33976 KB |
Output is correct |
4 |
Correct |
204 ms |
43972 KB |
Output is correct |
5 |
Correct |
380 ms |
54948 KB |
Output is correct |
6 |
Correct |
64 ms |
31940 KB |
Output is correct |
7 |
Correct |
115 ms |
48108 KB |
Output is correct |
8 |
Correct |
125 ms |
52156 KB |
Output is correct |
9 |
Correct |
15 ms |
23932 KB |
Output is correct |
10 |
Correct |
51 ms |
32024 KB |
Output is correct |
11 |
Correct |
136 ms |
51692 KB |
Output is correct |
12 |
Correct |
87 ms |
40012 KB |
Output is correct |
13 |
Correct |
12 ms |
23796 KB |
Output is correct |
14 |
Correct |
60 ms |
32632 KB |
Output is correct |
15 |
Correct |
13 ms |
23756 KB |
Output is correct |
16 |
Correct |
13 ms |
23712 KB |
Output is correct |
17 |
Correct |
12 ms |
23796 KB |
Output is correct |
18 |
Correct |
13 ms |
23804 KB |
Output is correct |
19 |
Correct |
12 ms |
23796 KB |
Output is correct |
20 |
Correct |
19 ms |
25548 KB |
Output is correct |
21 |
Correct |
12 ms |
23756 KB |
Output is correct |
22 |
Correct |
12 ms |
23716 KB |
Output is correct |
23 |
Correct |
12 ms |
23800 KB |
Output is correct |
24 |
Correct |
12 ms |
23748 KB |
Output is correct |
25 |
Correct |
12 ms |
23756 KB |
Output is correct |
26 |
Correct |
14 ms |
23872 KB |
Output is correct |
27 |
Correct |
15 ms |
23756 KB |
Output is correct |
28 |
Correct |
12 ms |
23800 KB |
Output is correct |
29 |
Correct |
14 ms |
23756 KB |
Output is correct |
30 |
Correct |
14 ms |
23796 KB |
Output is correct |
31 |
Correct |
12 ms |
23796 KB |
Output is correct |
32 |
Correct |
12 ms |
23884 KB |
Output is correct |
33 |
Correct |
12 ms |
24012 KB |
Output is correct |
34 |
Correct |
11 ms |
23756 KB |
Output is correct |
35 |
Correct |
12 ms |
23700 KB |
Output is correct |
36 |
Correct |
351 ms |
67636 KB |
Output is correct |
37 |
Correct |
217 ms |
56480 KB |
Output is correct |
38 |
Correct |
27 ms |
26000 KB |
Output is correct |
39 |
Correct |
18 ms |
24396 KB |
Output is correct |
40 |
Correct |
15 ms |
24396 KB |
Output is correct |
41 |
Correct |
15 ms |
24068 KB |
Output is correct |
42 |
Correct |
98 ms |
41468 KB |
Output is correct |
43 |
Correct |
52 ms |
31112 KB |
Output is correct |
44 |
Correct |
90 ms |
32752 KB |
Output is correct |
45 |
Correct |
13 ms |
23884 KB |
Output is correct |
46 |
Correct |
12 ms |
23808 KB |
Output is correct |
47 |
Correct |
187 ms |
64540 KB |
Output is correct |
48 |
Correct |
151 ms |
62064 KB |
Output is correct |
49 |
Correct |
173 ms |
42136 KB |
Output is correct |
50 |
Correct |
120 ms |
40076 KB |
Output is correct |
51 |
Correct |
155 ms |
41368 KB |
Output is correct |
52 |
Correct |
207 ms |
43752 KB |
Output is correct |
53 |
Correct |
85 ms |
33184 KB |
Output is correct |
54 |
Correct |
165 ms |
56896 KB |
Output is correct |
55 |
Correct |
348 ms |
54160 KB |
Output is correct |
56 |
Correct |
221 ms |
44224 KB |
Output is correct |
57 |
Correct |
229 ms |
47432 KB |
Output is correct |
58 |
Correct |
103 ms |
37040 KB |
Output is correct |
59 |
Correct |
242 ms |
52420 KB |
Output is correct |
60 |
Correct |
181 ms |
49704 KB |
Output is correct |
61 |
Incorrect |
151 ms |
47928 KB |
Output isn't correct |