#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,20) {
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));
reverse(all(z));
vector<pi> z2;
int r=0;
for (int i=0; i<k; ++i) {
r=max(r,i+1);
while (r<k && z[k].f+l>z[i].f) ++r;
if (r>=k) {
z2.pb(z[i]); continue;
}
int u=z[i].s, v=z[r].s;
adj[u].pb({v,l});
adj[v].pb({u,l});
++r;
}
k=z2.size();
forn(i,k/2) {
int u=z2[i].s, v=z2[(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;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
592 ms |
22168 KB |
Output is correct |
2 |
Correct |
568 ms |
17736 KB |
Output is correct |
3 |
Correct |
236 ms |
15212 KB |
Output is correct |
4 |
Correct |
60 ms |
5380 KB |
Output is correct |
5 |
Correct |
35 ms |
3988 KB |
Output is correct |
6 |
Correct |
79 ms |
5992 KB |
Output is correct |
7 |
Correct |
2 ms |
2644 KB |
Output is correct |
8 |
Correct |
186 ms |
9288 KB |
Output is correct |
9 |
Correct |
222 ms |
12504 KB |
Output is correct |
10 |
Correct |
3 ms |
2772 KB |
Output is correct |
11 |
Correct |
407 ms |
12648 KB |
Output is correct |
12 |
Correct |
377 ms |
16656 KB |
Output is correct |
13 |
Correct |
4 ms |
2772 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
2644 KB |
Output is correct |
2 |
Correct |
3 ms |
2644 KB |
Output is correct |
3 |
Correct |
2 ms |
2644 KB |
Output is correct |
4 |
Correct |
2 ms |
2644 KB |
Output is correct |
5 |
Correct |
3 ms |
2644 KB |
Output is correct |
6 |
Correct |
2 ms |
2644 KB |
Output is correct |
7 |
Correct |
2 ms |
2644 KB |
Output is correct |
8 |
Correct |
2 ms |
2644 KB |
Output is correct |
9 |
Correct |
2 ms |
2644 KB |
Output is correct |
10 |
Correct |
3 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 |
2 ms |
2644 KB |
Output is correct |
16 |
Correct |
2 ms |
2644 KB |
Output is correct |
17 |
Correct |
2 ms |
2644 KB |
Output is correct |
18 |
Correct |
2 ms |
2644 KB |
Output is correct |
19 |
Correct |
3 ms |
2644 KB |
Output is correct |
20 |
Correct |
3 ms |
2644 KB |
Output is correct |
21 |
Correct |
2 ms |
2644 KB |
Output is correct |
22 |
Correct |
2 ms |
2644 KB |
Output is correct |
23 |
Correct |
2 ms |
2644 KB |
Output is correct |
24 |
Correct |
2 ms |
2700 KB |
Output is correct |
25 |
Correct |
2 ms |
2644 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
592 ms |
22168 KB |
Output is correct |
2 |
Correct |
568 ms |
17736 KB |
Output is correct |
3 |
Correct |
236 ms |
15212 KB |
Output is correct |
4 |
Correct |
60 ms |
5380 KB |
Output is correct |
5 |
Correct |
35 ms |
3988 KB |
Output is correct |
6 |
Correct |
79 ms |
5992 KB |
Output is correct |
7 |
Correct |
2 ms |
2644 KB |
Output is correct |
8 |
Correct |
186 ms |
9288 KB |
Output is correct |
9 |
Correct |
222 ms |
12504 KB |
Output is correct |
10 |
Correct |
3 ms |
2772 KB |
Output is correct |
11 |
Correct |
407 ms |
12648 KB |
Output is correct |
12 |
Correct |
377 ms |
16656 KB |
Output is correct |
13 |
Correct |
4 ms |
2772 KB |
Output is correct |
14 |
Correct |
2 ms |
2644 KB |
Output is correct |
15 |
Correct |
3 ms |
2644 KB |
Output is correct |
16 |
Correct |
2 ms |
2644 KB |
Output is correct |
17 |
Correct |
2 ms |
2644 KB |
Output is correct |
18 |
Correct |
3 ms |
2644 KB |
Output is correct |
19 |
Correct |
2 ms |
2644 KB |
Output is correct |
20 |
Correct |
2 ms |
2644 KB |
Output is correct |
21 |
Correct |
2 ms |
2644 KB |
Output is correct |
22 |
Correct |
2 ms |
2644 KB |
Output is correct |
23 |
Correct |
3 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 |
2 ms |
2644 KB |
Output is correct |
29 |
Correct |
2 ms |
2644 KB |
Output is correct |
30 |
Correct |
2 ms |
2644 KB |
Output is correct |
31 |
Correct |
2 ms |
2644 KB |
Output is correct |
32 |
Correct |
3 ms |
2644 KB |
Output is correct |
33 |
Correct |
3 ms |
2644 KB |
Output is correct |
34 |
Correct |
2 ms |
2644 KB |
Output is correct |
35 |
Correct |
2 ms |
2644 KB |
Output is correct |
36 |
Correct |
2 ms |
2644 KB |
Output is correct |
37 |
Correct |
2 ms |
2700 KB |
Output is correct |
38 |
Correct |
2 ms |
2644 KB |
Output is correct |
39 |
Correct |
454 ms |
22188 KB |
Output is correct |
40 |
Correct |
596 ms |
17740 KB |
Output is correct |
41 |
Correct |
206 ms |
15208 KB |
Output is correct |
42 |
Correct |
53 ms |
5380 KB |
Output is correct |
43 |
Correct |
2 ms |
2644 KB |
Output is correct |
44 |
Correct |
2 ms |
2700 KB |
Output is correct |
45 |
Correct |
1 ms |
2644 KB |
Output is correct |
46 |
Correct |
1 ms |
2644 KB |
Output is correct |
47 |
Correct |
1 ms |
2644 KB |
Output is correct |
48 |
Correct |
2 ms |
2644 KB |
Output is correct |
49 |
Correct |
2 ms |
2644 KB |
Output is correct |
50 |
Correct |
1 ms |
2644 KB |
Output is correct |
51 |
Correct |
1 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 |
593 ms |
9920 KB |
Output is correct |
58 |
Correct |
434 ms |
9856 KB |
Output is correct |
59 |
Correct |
425 ms |
10292 KB |
Output is correct |
60 |
Correct |
659 ms |
9916 KB |
Output is correct |
61 |
Correct |
450 ms |
10072 KB |
Output is correct |
62 |
Correct |
422 ms |
10132 KB |
Output is correct |
63 |
Correct |
420 ms |
9924 KB |
Output is correct |
64 |
Correct |
407 ms |
9904 KB |
Output is correct |
65 |
Execution timed out |
1089 ms |
9848 KB |
Time limit exceeded |
66 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
720 ms |
12544 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
2644 KB |
Output is correct |
2 |
Correct |
3 ms |
2644 KB |
Output is correct |
3 |
Correct |
2 ms |
2644 KB |
Output is correct |
4 |
Correct |
2 ms |
2644 KB |
Output is correct |
5 |
Correct |
3 ms |
2644 KB |
Output is correct |
6 |
Correct |
2 ms |
2644 KB |
Output is correct |
7 |
Correct |
2 ms |
2644 KB |
Output is correct |
8 |
Correct |
2 ms |
2644 KB |
Output is correct |
9 |
Correct |
2 ms |
2644 KB |
Output is correct |
10 |
Correct |
3 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 |
2 ms |
2644 KB |
Output is correct |
16 |
Correct |
2 ms |
2644 KB |
Output is correct |
17 |
Correct |
2 ms |
2644 KB |
Output is correct |
18 |
Correct |
2 ms |
2644 KB |
Output is correct |
19 |
Correct |
3 ms |
2644 KB |
Output is correct |
20 |
Correct |
3 ms |
2644 KB |
Output is correct |
21 |
Correct |
2 ms |
2644 KB |
Output is correct |
22 |
Correct |
2 ms |
2644 KB |
Output is correct |
23 |
Correct |
2 ms |
2644 KB |
Output is correct |
24 |
Correct |
2 ms |
2700 KB |
Output is correct |
25 |
Correct |
2 ms |
2644 KB |
Output is correct |
26 |
Correct |
3 ms |
2772 KB |
Output is correct |
27 |
Incorrect |
6 ms |
2852 KB |
Output isn't correct |
28 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
592 ms |
22168 KB |
Output is correct |
2 |
Correct |
568 ms |
17736 KB |
Output is correct |
3 |
Correct |
236 ms |
15212 KB |
Output is correct |
4 |
Correct |
60 ms |
5380 KB |
Output is correct |
5 |
Correct |
35 ms |
3988 KB |
Output is correct |
6 |
Correct |
79 ms |
5992 KB |
Output is correct |
7 |
Correct |
2 ms |
2644 KB |
Output is correct |
8 |
Correct |
186 ms |
9288 KB |
Output is correct |
9 |
Correct |
222 ms |
12504 KB |
Output is correct |
10 |
Correct |
3 ms |
2772 KB |
Output is correct |
11 |
Correct |
407 ms |
12648 KB |
Output is correct |
12 |
Correct |
377 ms |
16656 KB |
Output is correct |
13 |
Correct |
4 ms |
2772 KB |
Output is correct |
14 |
Correct |
2 ms |
2644 KB |
Output is correct |
15 |
Correct |
3 ms |
2644 KB |
Output is correct |
16 |
Correct |
2 ms |
2644 KB |
Output is correct |
17 |
Correct |
2 ms |
2644 KB |
Output is correct |
18 |
Correct |
3 ms |
2644 KB |
Output is correct |
19 |
Correct |
2 ms |
2644 KB |
Output is correct |
20 |
Correct |
2 ms |
2644 KB |
Output is correct |
21 |
Correct |
2 ms |
2644 KB |
Output is correct |
22 |
Correct |
2 ms |
2644 KB |
Output is correct |
23 |
Correct |
3 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 |
2 ms |
2644 KB |
Output is correct |
29 |
Correct |
2 ms |
2644 KB |
Output is correct |
30 |
Correct |
2 ms |
2644 KB |
Output is correct |
31 |
Correct |
2 ms |
2644 KB |
Output is correct |
32 |
Correct |
3 ms |
2644 KB |
Output is correct |
33 |
Correct |
3 ms |
2644 KB |
Output is correct |
34 |
Correct |
2 ms |
2644 KB |
Output is correct |
35 |
Correct |
2 ms |
2644 KB |
Output is correct |
36 |
Correct |
2 ms |
2644 KB |
Output is correct |
37 |
Correct |
2 ms |
2700 KB |
Output is correct |
38 |
Correct |
2 ms |
2644 KB |
Output is correct |
39 |
Correct |
454 ms |
22188 KB |
Output is correct |
40 |
Correct |
596 ms |
17740 KB |
Output is correct |
41 |
Correct |
206 ms |
15208 KB |
Output is correct |
42 |
Correct |
53 ms |
5380 KB |
Output is correct |
43 |
Correct |
2 ms |
2644 KB |
Output is correct |
44 |
Correct |
2 ms |
2700 KB |
Output is correct |
45 |
Correct |
1 ms |
2644 KB |
Output is correct |
46 |
Correct |
1 ms |
2644 KB |
Output is correct |
47 |
Correct |
1 ms |
2644 KB |
Output is correct |
48 |
Correct |
2 ms |
2644 KB |
Output is correct |
49 |
Correct |
2 ms |
2644 KB |
Output is correct |
50 |
Correct |
1 ms |
2644 KB |
Output is correct |
51 |
Correct |
1 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 |
593 ms |
9920 KB |
Output is correct |
58 |
Correct |
434 ms |
9856 KB |
Output is correct |
59 |
Correct |
425 ms |
10292 KB |
Output is correct |
60 |
Correct |
659 ms |
9916 KB |
Output is correct |
61 |
Correct |
450 ms |
10072 KB |
Output is correct |
62 |
Correct |
422 ms |
10132 KB |
Output is correct |
63 |
Correct |
420 ms |
9924 KB |
Output is correct |
64 |
Correct |
407 ms |
9904 KB |
Output is correct |
65 |
Execution timed out |
1089 ms |
9848 KB |
Time limit exceeded |
66 |
Halted |
0 ms |
0 KB |
- |