#include <bits/stdc++.h>
#define FLASH ios_base::sync_with_stdio(0);
#define ll long long
#define debt(x,y)cout<<"#x = "<<(x)<<" and "<<"#y = "<<(y)<<endl;
#define deb(x)cout<<"#x = "<<(x)<<endl;
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(), (x).end()
#define endl "\n"
#define arr(a,n) for(ll i=1;i<=n;i++) cout<<a[i]<<" "; cout << "\n";
#define vecc(a,n) for(ll i=0;i<n;i++) cout<<a[i]<<" "; cout << "\n";
using namespace std;
unordered_map<ll,ll>adj1[300010];
vector<pair<ll,ll> >adj[300010];
ll sorthus(pair<ll,ll>a,pair<ll,ll>b)
{
return a.first>b.first;
}
ll n,m;
int main(){
FLASH;
cin>>n>>m;
for(ll i=1;i<=m;i++)
{
ll x,y,z;
cin>>x>>y>>z;
adj[x].pb(mp(z,y));
adj[y].pb(mp(z,x));
adj1[x][y]=z;
adj1[y][x]=z;
}
ll maxx=0;
ll summ=0;
for(ll i=1;i<=n;i++)
{
summ=0;
sort(all(adj[i]),sorthus);
for(auto j:adj1[i])summ+=j.second;
maxx=max(maxx,summ);
}
for(ll i=1;i<=n;i++)
{
if(adj[i].size()>=1)
{
auto one=adj[i][0];
if(adj[one.second].size()>=2)
{
auto two=adj[one.second][1];
maxx=max(maxx,one.first+two.first+adj1[two.second][i]);
}
}
}
cout<<maxx<<endl;
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
17 ms |
23808 KB |
Output is correct |
2 |
Correct |
17 ms |
23808 KB |
Output is correct |
3 |
Correct |
19 ms |
23808 KB |
Output is correct |
4 |
Correct |
19 ms |
23808 KB |
Output is correct |
5 |
Correct |
17 ms |
23808 KB |
Output is correct |
6 |
Correct |
32 ms |
26368 KB |
Output is correct |
7 |
Correct |
17 ms |
23808 KB |
Output is correct |
8 |
Correct |
17 ms |
23808 KB |
Output is correct |
9 |
Correct |
17 ms |
23808 KB |
Output is correct |
10 |
Correct |
19 ms |
23808 KB |
Output is correct |
11 |
Correct |
18 ms |
23936 KB |
Output is correct |
12 |
Correct |
18 ms |
23936 KB |
Output is correct |
13 |
Correct |
18 ms |
23808 KB |
Output is correct |
14 |
Correct |
17 ms |
23808 KB |
Output is correct |
15 |
Correct |
19 ms |
23808 KB |
Output is correct |
16 |
Correct |
17 ms |
23808 KB |
Output is correct |
17 |
Correct |
17 ms |
23808 KB |
Output is correct |
18 |
Correct |
19 ms |
24064 KB |
Output is correct |
19 |
Correct |
19 ms |
24064 KB |
Output is correct |
20 |
Correct |
17 ms |
23808 KB |
Output is correct |
21 |
Correct |
17 ms |
23808 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
17 ms |
23808 KB |
Output is correct |
2 |
Correct |
17 ms |
23808 KB |
Output is correct |
3 |
Correct |
19 ms |
23808 KB |
Output is correct |
4 |
Correct |
19 ms |
23808 KB |
Output is correct |
5 |
Correct |
17 ms |
23808 KB |
Output is correct |
6 |
Correct |
32 ms |
26368 KB |
Output is correct |
7 |
Correct |
17 ms |
23808 KB |
Output is correct |
8 |
Correct |
17 ms |
23808 KB |
Output is correct |
9 |
Correct |
17 ms |
23808 KB |
Output is correct |
10 |
Correct |
19 ms |
23808 KB |
Output is correct |
11 |
Correct |
18 ms |
23936 KB |
Output is correct |
12 |
Correct |
18 ms |
23936 KB |
Output is correct |
13 |
Correct |
18 ms |
23808 KB |
Output is correct |
14 |
Correct |
17 ms |
23808 KB |
Output is correct |
15 |
Correct |
19 ms |
23808 KB |
Output is correct |
16 |
Correct |
17 ms |
23808 KB |
Output is correct |
17 |
Correct |
17 ms |
23808 KB |
Output is correct |
18 |
Correct |
19 ms |
24064 KB |
Output is correct |
19 |
Correct |
19 ms |
24064 KB |
Output is correct |
20 |
Correct |
17 ms |
23808 KB |
Output is correct |
21 |
Correct |
17 ms |
23808 KB |
Output is correct |
22 |
Correct |
1285 ms |
88804 KB |
Output is correct |
23 |
Correct |
505 ms |
93644 KB |
Output is correct |
24 |
Correct |
37 ms |
26872 KB |
Output is correct |
25 |
Correct |
22 ms |
24704 KB |
Output is correct |
26 |
Correct |
24 ms |
24808 KB |
Output is correct |
27 |
Correct |
20 ms |
24188 KB |
Output is correct |
28 |
Correct |
397 ms |
51256 KB |
Output is correct |
29 |
Correct |
120 ms |
34424 KB |
Output is correct |
30 |
Correct |
246 ms |
41080 KB |
Output is correct |
31 |
Correct |
19 ms |
23936 KB |
Output is correct |
32 |
Correct |
18 ms |
23936 KB |
Output is correct |
33 |
Correct |
545 ms |
96760 KB |
Output is correct |
34 |
Correct |
447 ms |
89404 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
255 ms |
52044 KB |
Output is correct |
2 |
Correct |
584 ms |
78324 KB |
Output is correct |
3 |
Correct |
199 ms |
41976 KB |
Output is correct |
4 |
Correct |
370 ms |
59384 KB |
Output is correct |
5 |
Correct |
907 ms |
73488 KB |
Output is correct |
6 |
Correct |
115 ms |
40160 KB |
Output is correct |
7 |
Correct |
247 ms |
73152 KB |
Output is correct |
8 |
Correct |
269 ms |
75324 KB |
Output is correct |
9 |
Correct |
23 ms |
24064 KB |
Output is correct |
10 |
Correct |
113 ms |
40216 KB |
Output is correct |
11 |
Correct |
245 ms |
72996 KB |
Output is correct |
12 |
Correct |
201 ms |
56500 KB |
Output is correct |
13 |
Correct |
17 ms |
23808 KB |
Output is correct |
14 |
Correct |
177 ms |
37884 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
255 ms |
52044 KB |
Output is correct |
2 |
Correct |
584 ms |
78324 KB |
Output is correct |
3 |
Correct |
199 ms |
41976 KB |
Output is correct |
4 |
Correct |
370 ms |
59384 KB |
Output is correct |
5 |
Correct |
907 ms |
73488 KB |
Output is correct |
6 |
Correct |
115 ms |
40160 KB |
Output is correct |
7 |
Correct |
247 ms |
73152 KB |
Output is correct |
8 |
Correct |
269 ms |
75324 KB |
Output is correct |
9 |
Correct |
23 ms |
24064 KB |
Output is correct |
10 |
Correct |
113 ms |
40216 KB |
Output is correct |
11 |
Correct |
245 ms |
72996 KB |
Output is correct |
12 |
Correct |
201 ms |
56500 KB |
Output is correct |
13 |
Correct |
17 ms |
23808 KB |
Output is correct |
14 |
Correct |
177 ms |
37884 KB |
Output is correct |
15 |
Correct |
436 ms |
56188 KB |
Output is correct |
16 |
Correct |
433 ms |
53468 KB |
Output is correct |
17 |
Correct |
499 ms |
62212 KB |
Output is correct |
18 |
Correct |
617 ms |
65072 KB |
Output is correct |
19 |
Correct |
229 ms |
44856 KB |
Output is correct |
20 |
Correct |
603 ms |
70440 KB |
Output is correct |
21 |
Correct |
606 ms |
85496 KB |
Output is correct |
22 |
Correct |
394 ms |
64652 KB |
Output is correct |
23 |
Correct |
542 ms |
75548 KB |
Output is correct |
24 |
Correct |
294 ms |
45692 KB |
Output is correct |
25 |
Correct |
850 ms |
70680 KB |
Output is correct |
26 |
Correct |
588 ms |
65068 KB |
Output is correct |
27 |
Correct |
630 ms |
64504 KB |
Output is correct |
28 |
Correct |
17 ms |
23808 KB |
Output is correct |
29 |
Correct |
17 ms |
23808 KB |
Output is correct |
30 |
Correct |
19 ms |
23808 KB |
Output is correct |
31 |
Correct |
19 ms |
23808 KB |
Output is correct |
32 |
Correct |
17 ms |
23808 KB |
Output is correct |
33 |
Correct |
32 ms |
26368 KB |
Output is correct |
34 |
Correct |
17 ms |
23808 KB |
Output is correct |
35 |
Correct |
17 ms |
23808 KB |
Output is correct |
36 |
Correct |
17 ms |
23808 KB |
Output is correct |
37 |
Correct |
19 ms |
23808 KB |
Output is correct |
38 |
Correct |
18 ms |
23936 KB |
Output is correct |
39 |
Correct |
18 ms |
23936 KB |
Output is correct |
40 |
Correct |
18 ms |
23808 KB |
Output is correct |
41 |
Correct |
17 ms |
23808 KB |
Output is correct |
42 |
Correct |
19 ms |
23808 KB |
Output is correct |
43 |
Correct |
17 ms |
23808 KB |
Output is correct |
44 |
Correct |
17 ms |
23808 KB |
Output is correct |
45 |
Correct |
19 ms |
24064 KB |
Output is correct |
46 |
Correct |
19 ms |
24064 KB |
Output is correct |
47 |
Correct |
17 ms |
23808 KB |
Output is correct |
48 |
Correct |
17 ms |
23808 KB |
Output is correct |
49 |
Correct |
1285 ms |
88804 KB |
Output is correct |
50 |
Correct |
505 ms |
93644 KB |
Output is correct |
51 |
Correct |
37 ms |
26872 KB |
Output is correct |
52 |
Correct |
22 ms |
24704 KB |
Output is correct |
53 |
Correct |
24 ms |
24808 KB |
Output is correct |
54 |
Correct |
20 ms |
24188 KB |
Output is correct |
55 |
Correct |
397 ms |
51256 KB |
Output is correct |
56 |
Correct |
120 ms |
34424 KB |
Output is correct |
57 |
Correct |
246 ms |
41080 KB |
Output is correct |
58 |
Correct |
19 ms |
23936 KB |
Output is correct |
59 |
Correct |
18 ms |
23936 KB |
Output is correct |
60 |
Correct |
545 ms |
96760 KB |
Output is correct |
61 |
Correct |
447 ms |
89404 KB |
Output is correct |