#include "dreaming.h"
#include <bits/stdc++.h>
using namespace std;
#define forn(i,n) for(int i=0; i<n; ++i)
#define pb push_back
#define all(x) x.begin(), x.end()
#define pi pair<int,int>
#define f first
#define s second
using ll = long long;
struct DSU {
vector<int> p,sz;
DSU(int n) {
forn(i,n) p.pb(i), sz.pb(1);
}
int get(int u) {
return p[u]==u?u:get(p[u]);
}
void uni(int u, int v) {
u=get(u),v=get(v);
if (u==v) return;
if (sz[u]<sz[v]) swap(u,v);
sz[u]+=sz[v];
p[v]=u;
}
};
const int N=1e5+5;
vector<pi> adj[N];
bitset<N> vis;
int d[N], in[N];
void dfs(int u, int p) {
in[u]=0;
for(auto&e:adj[u]) {
int v=e.f, w=e.s;
if (v==p) continue;
d[v]=d[u]+w;
dfs(v,u);
in[u]=max(in[u],in[v]+w);
}
}
int ans=0;
pi find(int u, int p, int o) {
ans=max(ans,o+in[u]);
pi ret = {u, max(o,in[u])};
vector<int> sf={0};
reverse(all(adj[u]));
for(auto&e:adj[u]) {
int v=e.f, w=e.s;
if (v==p) continue;
sf.pb(max(sf.back(),in[v]+w));
}
reverse(all(adj[u]));
int mx=0;
for(auto&e:adj[u]) {
int v=e.f, w=e.s;
if (v==p) continue;
sf.pop_back();
auto x = find(v,u,max({o,mx,sf.back()})+w);
if (x.s<ret.s) ret=x;
mx=max(mx,in[v]+w);
}
return ret;
}
int travelTime(int n, int m, int l, int a[], int b[], int t[]) {
forn(i,m) {
int u=a[i],v=b[i],w=t[i];
adj[u].pb({v,w});
adj[v].pb({u,w});
}
forn(it,30) {
DSU dsu(n);
forn(i,n) for(auto&x:adj[i]) dsu.uni(i,x.f);
vis.reset();
vector<int> c;
forn(i,n) {
int u=dsu.get(i);
if (vis[u]) continue;
vis[u]=1;
c.pb(u);
}
int k=c.size();
vector<pi> z;
forn(i,k) {
d[c[i]]=0;
dfs(c[i],-1);
auto q=find(c[i],-1,0);
swap(q.f,q.s);
z.pb(q);
}
sort(all(z));
forn(i,k/2) {
int u=z[i].s, v=z[(k+1)/2+i].s;
adj[u].pb({v,l});
adj[v].pb({u,l});
}
}
ans=0;
d[0]=0;
dfs(0,-1);
find(0,-1,0);
return ans;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
578 ms |
22196 KB |
Output is correct |
2 |
Correct |
539 ms |
17608 KB |
Output is correct |
3 |
Correct |
296 ms |
15340 KB |
Output is correct |
4 |
Correct |
59 ms |
5392 KB |
Output is correct |
5 |
Correct |
50 ms |
3924 KB |
Output is correct |
6 |
Correct |
116 ms |
5984 KB |
Output is correct |
7 |
Correct |
2 ms |
2644 KB |
Output is correct |
8 |
Correct |
231 ms |
9252 KB |
Output is correct |
9 |
Correct |
294 ms |
12616 KB |
Output is correct |
10 |
Correct |
3 ms |
2772 KB |
Output is correct |
11 |
Correct |
444 ms |
12600 KB |
Output is correct |
12 |
Correct |
553 ms |
16524 KB |
Output is correct |
13 |
Correct |
5 ms |
2772 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
2644 KB |
Output is correct |
2 |
Correct |
2 ms |
2644 KB |
Output is correct |
3 |
Correct |
1 ms |
2644 KB |
Output is correct |
4 |
Correct |
1 ms |
2644 KB |
Output is correct |
5 |
Correct |
1 ms |
2644 KB |
Output is correct |
6 |
Correct |
1 ms |
2644 KB |
Output is correct |
7 |
Correct |
1 ms |
2644 KB |
Output is correct |
8 |
Correct |
1 ms |
2644 KB |
Output is correct |
9 |
Correct |
1 ms |
2644 KB |
Output is correct |
10 |
Correct |
1 ms |
2644 KB |
Output is correct |
11 |
Correct |
2 ms |
2644 KB |
Output is correct |
12 |
Correct |
2 ms |
2644 KB |
Output is correct |
13 |
Correct |
2 ms |
2644 KB |
Output is correct |
14 |
Correct |
2 ms |
2644 KB |
Output is correct |
15 |
Correct |
1 ms |
2644 KB |
Output is correct |
16 |
Correct |
1 ms |
2644 KB |
Output is correct |
17 |
Correct |
1 ms |
2644 KB |
Output is correct |
18 |
Correct |
1 ms |
2644 KB |
Output is correct |
19 |
Correct |
1 ms |
2644 KB |
Output is correct |
20 |
Correct |
1 ms |
2644 KB |
Output is correct |
21 |
Correct |
1 ms |
2644 KB |
Output is correct |
22 |
Correct |
2 ms |
2644 KB |
Output is correct |
23 |
Correct |
1 ms |
2644 KB |
Output is correct |
24 |
Correct |
1 ms |
2644 KB |
Output is correct |
25 |
Correct |
2 ms |
2644 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
578 ms |
22196 KB |
Output is correct |
2 |
Correct |
539 ms |
17608 KB |
Output is correct |
3 |
Correct |
296 ms |
15340 KB |
Output is correct |
4 |
Correct |
59 ms |
5392 KB |
Output is correct |
5 |
Correct |
50 ms |
3924 KB |
Output is correct |
6 |
Correct |
116 ms |
5984 KB |
Output is correct |
7 |
Correct |
2 ms |
2644 KB |
Output is correct |
8 |
Correct |
231 ms |
9252 KB |
Output is correct |
9 |
Correct |
294 ms |
12616 KB |
Output is correct |
10 |
Correct |
3 ms |
2772 KB |
Output is correct |
11 |
Correct |
444 ms |
12600 KB |
Output is correct |
12 |
Correct |
553 ms |
16524 KB |
Output is correct |
13 |
Correct |
5 ms |
2772 KB |
Output is correct |
14 |
Correct |
1 ms |
2644 KB |
Output is correct |
15 |
Correct |
2 ms |
2644 KB |
Output is correct |
16 |
Correct |
1 ms |
2644 KB |
Output is correct |
17 |
Correct |
1 ms |
2644 KB |
Output is correct |
18 |
Correct |
1 ms |
2644 KB |
Output is correct |
19 |
Correct |
1 ms |
2644 KB |
Output is correct |
20 |
Correct |
1 ms |
2644 KB |
Output is correct |
21 |
Correct |
1 ms |
2644 KB |
Output is correct |
22 |
Correct |
1 ms |
2644 KB |
Output is correct |
23 |
Correct |
1 ms |
2644 KB |
Output is correct |
24 |
Correct |
2 ms |
2644 KB |
Output is correct |
25 |
Correct |
2 ms |
2644 KB |
Output is correct |
26 |
Correct |
2 ms |
2644 KB |
Output is correct |
27 |
Correct |
2 ms |
2644 KB |
Output is correct |
28 |
Correct |
1 ms |
2644 KB |
Output is correct |
29 |
Correct |
1 ms |
2644 KB |
Output is correct |
30 |
Correct |
1 ms |
2644 KB |
Output is correct |
31 |
Correct |
1 ms |
2644 KB |
Output is correct |
32 |
Correct |
1 ms |
2644 KB |
Output is correct |
33 |
Correct |
1 ms |
2644 KB |
Output is correct |
34 |
Correct |
1 ms |
2644 KB |
Output is correct |
35 |
Correct |
2 ms |
2644 KB |
Output is correct |
36 |
Correct |
1 ms |
2644 KB |
Output is correct |
37 |
Correct |
1 ms |
2644 KB |
Output is correct |
38 |
Correct |
2 ms |
2644 KB |
Output is correct |
39 |
Correct |
589 ms |
22168 KB |
Output is correct |
40 |
Correct |
534 ms |
17584 KB |
Output is correct |
41 |
Correct |
311 ms |
15340 KB |
Output is correct |
42 |
Correct |
59 ms |
5372 KB |
Output is correct |
43 |
Correct |
2 ms |
2644 KB |
Output is correct |
44 |
Correct |
1 ms |
2644 KB |
Output is correct |
45 |
Correct |
2 ms |
2644 KB |
Output is correct |
46 |
Correct |
2 ms |
2644 KB |
Output is correct |
47 |
Correct |
1 ms |
2644 KB |
Output is correct |
48 |
Correct |
2 ms |
2588 KB |
Output is correct |
49 |
Correct |
1 ms |
2644 KB |
Output is correct |
50 |
Correct |
2 ms |
2644 KB |
Output is correct |
51 |
Correct |
2 ms |
2644 KB |
Output is correct |
52 |
Correct |
1 ms |
2644 KB |
Output is correct |
53 |
Correct |
1 ms |
2644 KB |
Output is correct |
54 |
Correct |
1 ms |
2644 KB |
Output is correct |
55 |
Correct |
2 ms |
2644 KB |
Output is correct |
56 |
Correct |
2 ms |
2644 KB |
Output is correct |
57 |
Correct |
561 ms |
9924 KB |
Output is correct |
58 |
Correct |
556 ms |
9880 KB |
Output is correct |
59 |
Correct |
618 ms |
10336 KB |
Output is correct |
60 |
Correct |
648 ms |
9880 KB |
Output is correct |
61 |
Correct |
576 ms |
10088 KB |
Output is correct |
62 |
Correct |
580 ms |
10092 KB |
Output is correct |
63 |
Correct |
540 ms |
9928 KB |
Output is correct |
64 |
Correct |
554 ms |
10024 KB |
Output is correct |
65 |
Correct |
550 ms |
9924 KB |
Output is correct |
66 |
Correct |
531 ms |
9948 KB |
Output is correct |
67 |
Correct |
615 ms |
9920 KB |
Output is correct |
68 |
Correct |
612 ms |
9908 KB |
Output is correct |
69 |
Correct |
620 ms |
9824 KB |
Output is correct |
70 |
Correct |
587 ms |
9800 KB |
Output is correct |
71 |
Correct |
1 ms |
2644 KB |
Output is correct |
72 |
Correct |
21 ms |
2940 KB |
Output is correct |
73 |
Correct |
17 ms |
2940 KB |
Output is correct |
74 |
Correct |
13 ms |
2900 KB |
Output is correct |
75 |
Correct |
14 ms |
2908 KB |
Output is correct |
76 |
Correct |
12 ms |
2916 KB |
Output is correct |
77 |
Correct |
12 ms |
2900 KB |
Output is correct |
78 |
Correct |
16 ms |
2928 KB |
Output is correct |
79 |
Correct |
13 ms |
2900 KB |
Output is correct |
80 |
Correct |
700 ms |
10188 KB |
Output is correct |
81 |
Correct |
851 ms |
10168 KB |
Output is correct |
82 |
Correct |
664 ms |
10096 KB |
Output is correct |
83 |
Correct |
651 ms |
9704 KB |
Output is correct |
84 |
Correct |
8 ms |
2772 KB |
Output is correct |
85 |
Correct |
7 ms |
2864 KB |
Output is correct |
86 |
Correct |
9 ms |
2772 KB |
Output is correct |
87 |
Correct |
15 ms |
2772 KB |
Output is correct |
88 |
Correct |
11 ms |
2772 KB |
Output is correct |
89 |
Correct |
11 ms |
2900 KB |
Output is correct |
90 |
Correct |
12 ms |
2904 KB |
Output is correct |
91 |
Correct |
14 ms |
2920 KB |
Output is correct |
92 |
Correct |
12 ms |
2904 KB |
Output is correct |
93 |
Correct |
12 ms |
2900 KB |
Output is correct |
94 |
Correct |
2 ms |
2644 KB |
Output is correct |
95 |
Correct |
1 ms |
2644 KB |
Output is correct |
96 |
Correct |
2 ms |
2644 KB |
Output is correct |
97 |
Correct |
2 ms |
2644 KB |
Output is correct |
98 |
Correct |
2 ms |
2644 KB |
Output is correct |
99 |
Correct |
1 ms |
2644 KB |
Output is correct |
100 |
Correct |
1 ms |
2644 KB |
Output is correct |
101 |
Correct |
2 ms |
2644 KB |
Output is correct |
102 |
Correct |
1 ms |
2644 KB |
Output is correct |
103 |
Correct |
2 ms |
2644 KB |
Output is correct |
104 |
Correct |
56 ms |
3924 KB |
Output is correct |
105 |
Correct |
132 ms |
5988 KB |
Output is correct |
106 |
Correct |
4 ms |
2644 KB |
Output is correct |
107 |
Correct |
265 ms |
9520 KB |
Output is correct |
108 |
Correct |
321 ms |
13140 KB |
Output is correct |
109 |
Correct |
4 ms |
2776 KB |
Output is correct |
110 |
Correct |
474 ms |
13772 KB |
Output is correct |
111 |
Correct |
670 ms |
17768 KB |
Output is correct |
112 |
Correct |
5 ms |
2772 KB |
Output is correct |
113 |
Execution timed out |
1075 ms |
20484 KB |
Time limit exceeded |
114 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
341 ms |
9744 KB |
Output is correct |
2 |
Correct |
375 ms |
9812 KB |
Output is correct |
3 |
Correct |
320 ms |
9808 KB |
Output is correct |
4 |
Correct |
440 ms |
9820 KB |
Output is correct |
5 |
Correct |
305 ms |
9796 KB |
Output is correct |
6 |
Correct |
408 ms |
10188 KB |
Output is correct |
7 |
Correct |
346 ms |
10048 KB |
Output is correct |
8 |
Correct |
295 ms |
9448 KB |
Output is correct |
9 |
Correct |
322 ms |
9408 KB |
Output is correct |
10 |
Correct |
330 ms |
9984 KB |
Output is correct |
11 |
Incorrect |
2 ms |
2644 KB |
Output isn't correct |
12 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
2644 KB |
Output is correct |
2 |
Correct |
2 ms |
2644 KB |
Output is correct |
3 |
Correct |
1 ms |
2644 KB |
Output is correct |
4 |
Correct |
1 ms |
2644 KB |
Output is correct |
5 |
Correct |
1 ms |
2644 KB |
Output is correct |
6 |
Correct |
1 ms |
2644 KB |
Output is correct |
7 |
Correct |
1 ms |
2644 KB |
Output is correct |
8 |
Correct |
1 ms |
2644 KB |
Output is correct |
9 |
Correct |
1 ms |
2644 KB |
Output is correct |
10 |
Correct |
1 ms |
2644 KB |
Output is correct |
11 |
Correct |
2 ms |
2644 KB |
Output is correct |
12 |
Correct |
2 ms |
2644 KB |
Output is correct |
13 |
Correct |
2 ms |
2644 KB |
Output is correct |
14 |
Correct |
2 ms |
2644 KB |
Output is correct |
15 |
Correct |
1 ms |
2644 KB |
Output is correct |
16 |
Correct |
1 ms |
2644 KB |
Output is correct |
17 |
Correct |
1 ms |
2644 KB |
Output is correct |
18 |
Correct |
1 ms |
2644 KB |
Output is correct |
19 |
Correct |
1 ms |
2644 KB |
Output is correct |
20 |
Correct |
1 ms |
2644 KB |
Output is correct |
21 |
Correct |
1 ms |
2644 KB |
Output is correct |
22 |
Correct |
2 ms |
2644 KB |
Output is correct |
23 |
Correct |
1 ms |
2644 KB |
Output is correct |
24 |
Correct |
1 ms |
2644 KB |
Output is correct |
25 |
Correct |
2 ms |
2644 KB |
Output is correct |
26 |
Correct |
6 ms |
2644 KB |
Output is correct |
27 |
Correct |
8 ms |
2772 KB |
Output is correct |
28 |
Correct |
12 ms |
2948 KB |
Output is correct |
29 |
Incorrect |
4 ms |
2644 KB |
Output isn't correct |
30 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
578 ms |
22196 KB |
Output is correct |
2 |
Correct |
539 ms |
17608 KB |
Output is correct |
3 |
Correct |
296 ms |
15340 KB |
Output is correct |
4 |
Correct |
59 ms |
5392 KB |
Output is correct |
5 |
Correct |
50 ms |
3924 KB |
Output is correct |
6 |
Correct |
116 ms |
5984 KB |
Output is correct |
7 |
Correct |
2 ms |
2644 KB |
Output is correct |
8 |
Correct |
231 ms |
9252 KB |
Output is correct |
9 |
Correct |
294 ms |
12616 KB |
Output is correct |
10 |
Correct |
3 ms |
2772 KB |
Output is correct |
11 |
Correct |
444 ms |
12600 KB |
Output is correct |
12 |
Correct |
553 ms |
16524 KB |
Output is correct |
13 |
Correct |
5 ms |
2772 KB |
Output is correct |
14 |
Correct |
1 ms |
2644 KB |
Output is correct |
15 |
Correct |
2 ms |
2644 KB |
Output is correct |
16 |
Correct |
1 ms |
2644 KB |
Output is correct |
17 |
Correct |
1 ms |
2644 KB |
Output is correct |
18 |
Correct |
1 ms |
2644 KB |
Output is correct |
19 |
Correct |
1 ms |
2644 KB |
Output is correct |
20 |
Correct |
1 ms |
2644 KB |
Output is correct |
21 |
Correct |
1 ms |
2644 KB |
Output is correct |
22 |
Correct |
1 ms |
2644 KB |
Output is correct |
23 |
Correct |
1 ms |
2644 KB |
Output is correct |
24 |
Correct |
2 ms |
2644 KB |
Output is correct |
25 |
Correct |
2 ms |
2644 KB |
Output is correct |
26 |
Correct |
2 ms |
2644 KB |
Output is correct |
27 |
Correct |
2 ms |
2644 KB |
Output is correct |
28 |
Correct |
1 ms |
2644 KB |
Output is correct |
29 |
Correct |
1 ms |
2644 KB |
Output is correct |
30 |
Correct |
1 ms |
2644 KB |
Output is correct |
31 |
Correct |
1 ms |
2644 KB |
Output is correct |
32 |
Correct |
1 ms |
2644 KB |
Output is correct |
33 |
Correct |
1 ms |
2644 KB |
Output is correct |
34 |
Correct |
1 ms |
2644 KB |
Output is correct |
35 |
Correct |
2 ms |
2644 KB |
Output is correct |
36 |
Correct |
1 ms |
2644 KB |
Output is correct |
37 |
Correct |
1 ms |
2644 KB |
Output is correct |
38 |
Correct |
2 ms |
2644 KB |
Output is correct |
39 |
Correct |
589 ms |
22168 KB |
Output is correct |
40 |
Correct |
534 ms |
17584 KB |
Output is correct |
41 |
Correct |
311 ms |
15340 KB |
Output is correct |
42 |
Correct |
59 ms |
5372 KB |
Output is correct |
43 |
Correct |
2 ms |
2644 KB |
Output is correct |
44 |
Correct |
1 ms |
2644 KB |
Output is correct |
45 |
Correct |
2 ms |
2644 KB |
Output is correct |
46 |
Correct |
2 ms |
2644 KB |
Output is correct |
47 |
Correct |
1 ms |
2644 KB |
Output is correct |
48 |
Correct |
2 ms |
2588 KB |
Output is correct |
49 |
Correct |
1 ms |
2644 KB |
Output is correct |
50 |
Correct |
2 ms |
2644 KB |
Output is correct |
51 |
Correct |
2 ms |
2644 KB |
Output is correct |
52 |
Correct |
1 ms |
2644 KB |
Output is correct |
53 |
Correct |
1 ms |
2644 KB |
Output is correct |
54 |
Correct |
1 ms |
2644 KB |
Output is correct |
55 |
Correct |
2 ms |
2644 KB |
Output is correct |
56 |
Correct |
2 ms |
2644 KB |
Output is correct |
57 |
Correct |
561 ms |
9924 KB |
Output is correct |
58 |
Correct |
556 ms |
9880 KB |
Output is correct |
59 |
Correct |
618 ms |
10336 KB |
Output is correct |
60 |
Correct |
648 ms |
9880 KB |
Output is correct |
61 |
Correct |
576 ms |
10088 KB |
Output is correct |
62 |
Correct |
580 ms |
10092 KB |
Output is correct |
63 |
Correct |
540 ms |
9928 KB |
Output is correct |
64 |
Correct |
554 ms |
10024 KB |
Output is correct |
65 |
Correct |
550 ms |
9924 KB |
Output is correct |
66 |
Correct |
531 ms |
9948 KB |
Output is correct |
67 |
Correct |
615 ms |
9920 KB |
Output is correct |
68 |
Correct |
612 ms |
9908 KB |
Output is correct |
69 |
Correct |
620 ms |
9824 KB |
Output is correct |
70 |
Correct |
587 ms |
9800 KB |
Output is correct |
71 |
Correct |
1 ms |
2644 KB |
Output is correct |
72 |
Correct |
21 ms |
2940 KB |
Output is correct |
73 |
Correct |
17 ms |
2940 KB |
Output is correct |
74 |
Correct |
13 ms |
2900 KB |
Output is correct |
75 |
Correct |
14 ms |
2908 KB |
Output is correct |
76 |
Correct |
12 ms |
2916 KB |
Output is correct |
77 |
Correct |
12 ms |
2900 KB |
Output is correct |
78 |
Correct |
16 ms |
2928 KB |
Output is correct |
79 |
Correct |
13 ms |
2900 KB |
Output is correct |
80 |
Correct |
700 ms |
10188 KB |
Output is correct |
81 |
Correct |
851 ms |
10168 KB |
Output is correct |
82 |
Correct |
664 ms |
10096 KB |
Output is correct |
83 |
Correct |
651 ms |
9704 KB |
Output is correct |
84 |
Correct |
8 ms |
2772 KB |
Output is correct |
85 |
Correct |
7 ms |
2864 KB |
Output is correct |
86 |
Correct |
9 ms |
2772 KB |
Output is correct |
87 |
Correct |
15 ms |
2772 KB |
Output is correct |
88 |
Correct |
11 ms |
2772 KB |
Output is correct |
89 |
Correct |
11 ms |
2900 KB |
Output is correct |
90 |
Correct |
12 ms |
2904 KB |
Output is correct |
91 |
Correct |
14 ms |
2920 KB |
Output is correct |
92 |
Correct |
12 ms |
2904 KB |
Output is correct |
93 |
Correct |
12 ms |
2900 KB |
Output is correct |
94 |
Correct |
2 ms |
2644 KB |
Output is correct |
95 |
Correct |
1 ms |
2644 KB |
Output is correct |
96 |
Correct |
2 ms |
2644 KB |
Output is correct |
97 |
Correct |
2 ms |
2644 KB |
Output is correct |
98 |
Correct |
2 ms |
2644 KB |
Output is correct |
99 |
Correct |
1 ms |
2644 KB |
Output is correct |
100 |
Correct |
1 ms |
2644 KB |
Output is correct |
101 |
Correct |
2 ms |
2644 KB |
Output is correct |
102 |
Correct |
1 ms |
2644 KB |
Output is correct |
103 |
Correct |
2 ms |
2644 KB |
Output is correct |
104 |
Correct |
56 ms |
3924 KB |
Output is correct |
105 |
Correct |
132 ms |
5988 KB |
Output is correct |
106 |
Correct |
4 ms |
2644 KB |
Output is correct |
107 |
Correct |
265 ms |
9520 KB |
Output is correct |
108 |
Correct |
321 ms |
13140 KB |
Output is correct |
109 |
Correct |
4 ms |
2776 KB |
Output is correct |
110 |
Correct |
474 ms |
13772 KB |
Output is correct |
111 |
Correct |
670 ms |
17768 KB |
Output is correct |
112 |
Correct |
5 ms |
2772 KB |
Output is correct |
113 |
Execution timed out |
1075 ms |
20484 KB |
Time limit exceeded |
114 |
Halted |
0 ms |
0 KB |
- |