#include <bits/stdc++.h>
using namespace std;
#define vi vector<int>
#define vll vector<ll>
#define vii vector<pair<int, int>>
#define pii pair<int, int>
#define pll pair<ll, ll>
#define loop(_) for (int __ = 0; __ < (_); ++__)
#define pb push_back
#define f first
#define s second
#define sz(_) ((int)_.size())
#define all(_) _.begin(), _.end()
#define lb lower_bound
#define ub upper_bound
using ll = long long;
using ld = long double;
const int N = 3e5 + 7;
const ll mod = 1e9 + 7;
int n, m;
ll a[N];
int viz[N], col = 1;
ll ans;
map<pii, ll> cost;
vi adj[N];
vi adj2[N];
vii e , e2 ;
ll disto[N];
int fat[N];
void dfs(int x, int p = 0, int pp = 0)
{
viz[x] = col;
fat[x] = p;
for (auto u : adj[x])
{
if (u == p)
continue;
if (viz[u] != col)
{
dfs(u, x, p);
}
else
{
e2.pb({u, x});
if (p && pp && u == pp)
{
ans = max(ans, cost[{p, pp}] + cost[{x, p}] + cost[{x, pp}]);
}
adj2[x].pb(u);
}
}
}
void dfz(int x, int p)
{
if (p)
{
for (auto u : adj2[x])
{
ans = max(ans, cost[{x, p}] + disto[u] + cost[{x, u}]);
}
for (auto u : adj2[p])
{
disto[u] = -2e12;
}
}
for (auto u : adj2[x])
{
disto[u] = cost[{x, u}];
}
for (auto u : adj[x])
{
if (fat[u] == x)
dfz(u, x);
}
}
void prep(vi &act, vii &e)
{
act.clear();
for (auto u : e)
{
act.pb(u.f);
act.pb(u.s);
}
for(auto u :act){
adj[u].clear() ;
adj2[u].clear() ;
}
for(auto u : e){
adj[u.f].pb(u.s) ;
adj[u.s].pb(u.f);
}
}
int main()
{
ios_base::sync_with_stdio(0);
cin.tie(0);
#ifndef ONLINE_JUDGE
#endif
cin >> n >> m;
for (int i = 0; i < N; ++i)
disto[i] = -2e12;
vi act;
for (int i = 0; i < m; ++i)
{
int u, v, w;
cin >> u >> v >> w;
a[u] += w;
a[v] += w;
ans = max({ans, a[u], a[v]});
e.pb({u, v});
cost[{u, v}] = cost[{v, u}] = w;
}
while (sz(e))
{
prep(act, e);
for (auto u : act)
{
if (viz[u] != col)
{
dfs(u, 0, 0);
dfz(u, 0);
}
}
e = e2;
++col;
break;
}
cout << ans;
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
11 ms |
16768 KB |
Output is correct |
2 |
Correct |
11 ms |
16748 KB |
Output is correct |
3 |
Correct |
10 ms |
16748 KB |
Output is correct |
4 |
Correct |
10 ms |
16748 KB |
Output is correct |
5 |
Correct |
12 ms |
16748 KB |
Output is correct |
6 |
Correct |
34 ms |
20668 KB |
Output is correct |
7 |
Correct |
11 ms |
16748 KB |
Output is correct |
8 |
Correct |
10 ms |
16748 KB |
Output is correct |
9 |
Correct |
14 ms |
16876 KB |
Output is correct |
10 |
Correct |
11 ms |
16748 KB |
Output is correct |
11 |
Correct |
14 ms |
16876 KB |
Output is correct |
12 |
Correct |
11 ms |
16876 KB |
Output is correct |
13 |
Correct |
11 ms |
16876 KB |
Output is correct |
14 |
Correct |
11 ms |
16748 KB |
Output is correct |
15 |
Correct |
11 ms |
16748 KB |
Output is correct |
16 |
Correct |
11 ms |
16748 KB |
Output is correct |
17 |
Correct |
11 ms |
16748 KB |
Output is correct |
18 |
Correct |
12 ms |
17004 KB |
Output is correct |
19 |
Correct |
14 ms |
17260 KB |
Output is correct |
20 |
Correct |
11 ms |
16876 KB |
Output is correct |
21 |
Correct |
11 ms |
16748 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
11 ms |
16768 KB |
Output is correct |
2 |
Correct |
11 ms |
16748 KB |
Output is correct |
3 |
Correct |
10 ms |
16748 KB |
Output is correct |
4 |
Correct |
10 ms |
16748 KB |
Output is correct |
5 |
Correct |
12 ms |
16748 KB |
Output is correct |
6 |
Correct |
34 ms |
20668 KB |
Output is correct |
7 |
Correct |
11 ms |
16748 KB |
Output is correct |
8 |
Correct |
10 ms |
16748 KB |
Output is correct |
9 |
Correct |
14 ms |
16876 KB |
Output is correct |
10 |
Correct |
11 ms |
16748 KB |
Output is correct |
11 |
Correct |
14 ms |
16876 KB |
Output is correct |
12 |
Correct |
11 ms |
16876 KB |
Output is correct |
13 |
Correct |
11 ms |
16876 KB |
Output is correct |
14 |
Correct |
11 ms |
16748 KB |
Output is correct |
15 |
Correct |
11 ms |
16748 KB |
Output is correct |
16 |
Correct |
11 ms |
16748 KB |
Output is correct |
17 |
Correct |
11 ms |
16748 KB |
Output is correct |
18 |
Correct |
12 ms |
17004 KB |
Output is correct |
19 |
Correct |
14 ms |
17260 KB |
Output is correct |
20 |
Correct |
11 ms |
16876 KB |
Output is correct |
21 |
Correct |
11 ms |
16748 KB |
Output is correct |
22 |
Correct |
1774 ms |
114600 KB |
Output is correct |
23 |
Correct |
802 ms |
111268 KB |
Output is correct |
24 |
Correct |
45 ms |
21092 KB |
Output is correct |
25 |
Correct |
20 ms |
18156 KB |
Output is correct |
26 |
Correct |
20 ms |
18156 KB |
Output is correct |
27 |
Correct |
16 ms |
17260 KB |
Output is correct |
28 |
Correct |
610 ms |
56008 KB |
Output is correct |
29 |
Correct |
183 ms |
32736 KB |
Output is correct |
30 |
Correct |
330 ms |
40640 KB |
Output is correct |
31 |
Correct |
12 ms |
17004 KB |
Output is correct |
32 |
Correct |
11 ms |
17004 KB |
Output is correct |
33 |
Correct |
1033 ms |
112028 KB |
Output is correct |
34 |
Correct |
921 ms |
104260 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
315 ms |
52056 KB |
Output is correct |
2 |
Correct |
825 ms |
77904 KB |
Output is correct |
3 |
Correct |
203 ms |
37240 KB |
Output is correct |
4 |
Correct |
400 ms |
55024 KB |
Output is correct |
5 |
Correct |
1237 ms |
89304 KB |
Output is correct |
6 |
Correct |
183 ms |
40408 KB |
Output is correct |
7 |
Correct |
275 ms |
83040 KB |
Output is correct |
8 |
Correct |
364 ms |
81104 KB |
Output is correct |
9 |
Correct |
15 ms |
21612 KB |
Output is correct |
10 |
Correct |
186 ms |
40448 KB |
Output is correct |
11 |
Correct |
411 ms |
77648 KB |
Output is correct |
12 |
Correct |
502 ms |
64284 KB |
Output is correct |
13 |
Correct |
11 ms |
16748 KB |
Output is correct |
14 |
Correct |
248 ms |
36576 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
315 ms |
52056 KB |
Output is correct |
2 |
Correct |
825 ms |
77904 KB |
Output is correct |
3 |
Correct |
203 ms |
37240 KB |
Output is correct |
4 |
Correct |
400 ms |
55024 KB |
Output is correct |
5 |
Correct |
1237 ms |
89304 KB |
Output is correct |
6 |
Correct |
183 ms |
40408 KB |
Output is correct |
7 |
Correct |
275 ms |
83040 KB |
Output is correct |
8 |
Correct |
364 ms |
81104 KB |
Output is correct |
9 |
Correct |
15 ms |
21612 KB |
Output is correct |
10 |
Correct |
186 ms |
40448 KB |
Output is correct |
11 |
Correct |
411 ms |
77648 KB |
Output is correct |
12 |
Correct |
502 ms |
64284 KB |
Output is correct |
13 |
Correct |
11 ms |
16748 KB |
Output is correct |
14 |
Correct |
248 ms |
36576 KB |
Output is correct |
15 |
Correct |
11 ms |
16768 KB |
Output is correct |
16 |
Correct |
11 ms |
16748 KB |
Output is correct |
17 |
Correct |
10 ms |
16748 KB |
Output is correct |
18 |
Correct |
10 ms |
16748 KB |
Output is correct |
19 |
Correct |
12 ms |
16748 KB |
Output is correct |
20 |
Correct |
34 ms |
20668 KB |
Output is correct |
21 |
Correct |
11 ms |
16748 KB |
Output is correct |
22 |
Correct |
10 ms |
16748 KB |
Output is correct |
23 |
Correct |
14 ms |
16876 KB |
Output is correct |
24 |
Correct |
11 ms |
16748 KB |
Output is correct |
25 |
Correct |
14 ms |
16876 KB |
Output is correct |
26 |
Correct |
11 ms |
16876 KB |
Output is correct |
27 |
Correct |
11 ms |
16876 KB |
Output is correct |
28 |
Correct |
11 ms |
16748 KB |
Output is correct |
29 |
Correct |
11 ms |
16748 KB |
Output is correct |
30 |
Correct |
11 ms |
16748 KB |
Output is correct |
31 |
Correct |
11 ms |
16748 KB |
Output is correct |
32 |
Correct |
12 ms |
17004 KB |
Output is correct |
33 |
Correct |
14 ms |
17260 KB |
Output is correct |
34 |
Correct |
11 ms |
16876 KB |
Output is correct |
35 |
Correct |
11 ms |
16748 KB |
Output is correct |
36 |
Correct |
1774 ms |
114600 KB |
Output is correct |
37 |
Correct |
802 ms |
111268 KB |
Output is correct |
38 |
Correct |
45 ms |
21092 KB |
Output is correct |
39 |
Correct |
20 ms |
18156 KB |
Output is correct |
40 |
Correct |
20 ms |
18156 KB |
Output is correct |
41 |
Correct |
16 ms |
17260 KB |
Output is correct |
42 |
Correct |
610 ms |
56008 KB |
Output is correct |
43 |
Correct |
183 ms |
32736 KB |
Output is correct |
44 |
Correct |
330 ms |
40640 KB |
Output is correct |
45 |
Correct |
12 ms |
17004 KB |
Output is correct |
46 |
Correct |
11 ms |
17004 KB |
Output is correct |
47 |
Correct |
1033 ms |
112028 KB |
Output is correct |
48 |
Correct |
921 ms |
104260 KB |
Output is correct |
49 |
Correct |
710 ms |
56916 KB |
Output is correct |
50 |
Correct |
691 ms |
54680 KB |
Output is correct |
51 |
Correct |
589 ms |
58988 KB |
Output is correct |
52 |
Correct |
994 ms |
70224 KB |
Output is correct |
53 |
Correct |
174 ms |
35812 KB |
Output is correct |
54 |
Correct |
1008 ms |
77512 KB |
Output is correct |
55 |
Correct |
755 ms |
120272 KB |
Output is correct |
56 |
Correct |
453 ms |
85692 KB |
Output is correct |
57 |
Correct |
539 ms |
72408 KB |
Output is correct |
58 |
Correct |
482 ms |
45784 KB |
Output is correct |
59 |
Correct |
1010 ms |
79056 KB |
Output is correct |
60 |
Incorrect |
1116 ms |
72272 KB |
Output isn't correct |
61 |
Halted |
0 ms |
0 KB |
- |