#include "dreaming.h"
#include <bits/stdc++.h>
#define y second
#define x first
#define ll long long int
#define pb push_back
#define pii pair<int,int>
using namespace std;
const int N=1e5+7;
vector<pair<int,int> > adj[N];
bool vis[N];
void dfs(int node, int pnode, int dep, pair <int, int> &ret){
vis[node] = 1;
if(dep > ret.second)
ret = make_pair(node, dep);
for(auto &i : adj[node])
if(i.first != pnode)
dfs(i.first, node, dep + i.second, ret);
}
bool fn(int s,int e,int p,vector<int> &path){
if(s==e) {
return true;
}
for(auto v:adj[s]) {
if(v.x==p) continue;
if(fn(v.x,e,s,path)) {
path.push_back(v.x);
return true;
}
}
return false;
}
int travelTime(int N, int M, int L, int A[], int B[], int T[]) {
int n=N;
int m=M;
int l=L;
vector<int> radius;
map<pair<int,int>,int> cost;
for(int i=0; i<M; i++) {
int u=A[i];
int v=B[i];
int w=T[i];
adj[u].pb({v,w});
adj[v].pb({u,w});
cost[{u,v}]=cost[{v,u}]=w;
}
int d=0;
for(int i=0; i<n; i++) {
if(vis[i]) continue;
pii s={-1,-1};
dfs(i,-1,0,s);
pii e={-1,-1};
dfs(s.first,-1,0,e);
int diameter=e.y;
vector<int> path;
fn(s.x,e.x,0,path);
int sz=(int)path.size();
int rad=diameter;
int cur=diameter;
d=max(d,diameter);
for(int j=1; j<sz; j++) {
cur-=cost[{path[j],path[j-1]}];
rad=min(rad,max(diameter-cur,cur));
}
radius.push_back(rad);
}
int szz=(int)radius.size();
if(szz==1) return d;
sort(radius.rbegin(),radius.rend());
if(szz==2) {
// lol=max(lol,radius[0]+radius[1]+l);
return max(d,radius[0]+radius[1]+l);
}
return max(d,max(radius[0]+radius[1]+l,radius[1]+radius[2]+2*l));
}
Compilation message
dreaming.cpp: In function 'int travelTime(int, int, int, int*, int*, int*)':
dreaming.cpp:35:6: warning: unused variable 'm' [-Wunused-variable]
int m=M;
^
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
262 ms |
27380 KB |
Output is correct |
2 |
Correct |
284 ms |
27248 KB |
Output is correct |
3 |
Correct |
159 ms |
18808 KB |
Output is correct |
4 |
Correct |
24 ms |
6400 KB |
Output is correct |
5 |
Correct |
23 ms |
4864 KB |
Output is correct |
6 |
Correct |
46 ms |
8164 KB |
Output is correct |
7 |
Correct |
4 ms |
2816 KB |
Output is correct |
8 |
Correct |
113 ms |
11864 KB |
Output is correct |
9 |
Correct |
161 ms |
15264 KB |
Output is correct |
10 |
Correct |
4 ms |
2816 KB |
Output is correct |
11 |
Correct |
230 ms |
19320 KB |
Output is correct |
12 |
Correct |
322 ms |
23416 KB |
Output is correct |
13 |
Correct |
5 ms |
2944 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
262 ms |
27380 KB |
Output is correct |
2 |
Correct |
284 ms |
27248 KB |
Output is correct |
3 |
Correct |
159 ms |
18808 KB |
Output is correct |
4 |
Correct |
24 ms |
6400 KB |
Output is correct |
5 |
Correct |
23 ms |
4864 KB |
Output is correct |
6 |
Correct |
46 ms |
8164 KB |
Output is correct |
7 |
Correct |
4 ms |
2816 KB |
Output is correct |
8 |
Correct |
113 ms |
11864 KB |
Output is correct |
9 |
Correct |
161 ms |
15264 KB |
Output is correct |
10 |
Correct |
4 ms |
2816 KB |
Output is correct |
11 |
Correct |
230 ms |
19320 KB |
Output is correct |
12 |
Correct |
322 ms |
23416 KB |
Output is correct |
13 |
Correct |
5 ms |
2944 KB |
Output is correct |
14 |
Correct |
4 ms |
2688 KB |
Output is correct |
15 |
Correct |
4 ms |
2688 KB |
Output is correct |
16 |
Correct |
4 ms |
2688 KB |
Output is correct |
17 |
Correct |
4 ms |
2732 KB |
Output is correct |
18 |
Correct |
4 ms |
2688 KB |
Output is correct |
19 |
Correct |
4 ms |
2688 KB |
Output is correct |
20 |
Correct |
4 ms |
2688 KB |
Output is correct |
21 |
Correct |
4 ms |
2688 KB |
Output is correct |
22 |
Correct |
4 ms |
2688 KB |
Output is correct |
23 |
Correct |
4 ms |
2688 KB |
Output is correct |
24 |
Correct |
4 ms |
2688 KB |
Output is correct |
25 |
Correct |
4 ms |
2688 KB |
Output is correct |
26 |
Correct |
4 ms |
2688 KB |
Output is correct |
27 |
Correct |
4 ms |
2688 KB |
Output is correct |
28 |
Correct |
3 ms |
2688 KB |
Output is correct |
29 |
Correct |
4 ms |
2688 KB |
Output is correct |
30 |
Correct |
3 ms |
2688 KB |
Output is correct |
31 |
Correct |
3 ms |
2688 KB |
Output is correct |
32 |
Correct |
4 ms |
2688 KB |
Output is correct |
33 |
Correct |
3 ms |
2688 KB |
Output is correct |
34 |
Correct |
4 ms |
2688 KB |
Output is correct |
35 |
Correct |
4 ms |
2688 KB |
Output is correct |
36 |
Correct |
3 ms |
2688 KB |
Output is correct |
37 |
Correct |
4 ms |
2688 KB |
Output is correct |
38 |
Correct |
4 ms |
2688 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
262 ms |
27380 KB |
Output is correct |
2 |
Correct |
284 ms |
27248 KB |
Output is correct |
3 |
Correct |
159 ms |
18808 KB |
Output is correct |
4 |
Correct |
24 ms |
6400 KB |
Output is correct |
5 |
Correct |
23 ms |
4864 KB |
Output is correct |
6 |
Correct |
46 ms |
8164 KB |
Output is correct |
7 |
Correct |
4 ms |
2816 KB |
Output is correct |
8 |
Correct |
113 ms |
11864 KB |
Output is correct |
9 |
Correct |
161 ms |
15264 KB |
Output is correct |
10 |
Correct |
4 ms |
2816 KB |
Output is correct |
11 |
Correct |
230 ms |
19320 KB |
Output is correct |
12 |
Correct |
322 ms |
23416 KB |
Output is correct |
13 |
Correct |
5 ms |
2944 KB |
Output is correct |
14 |
Correct |
4 ms |
2688 KB |
Output is correct |
15 |
Correct |
4 ms |
2688 KB |
Output is correct |
16 |
Correct |
4 ms |
2688 KB |
Output is correct |
17 |
Correct |
4 ms |
2732 KB |
Output is correct |
18 |
Correct |
4 ms |
2688 KB |
Output is correct |
19 |
Correct |
4 ms |
2688 KB |
Output is correct |
20 |
Correct |
4 ms |
2688 KB |
Output is correct |
21 |
Correct |
4 ms |
2688 KB |
Output is correct |
22 |
Correct |
4 ms |
2688 KB |
Output is correct |
23 |
Correct |
4 ms |
2688 KB |
Output is correct |
24 |
Correct |
4 ms |
2688 KB |
Output is correct |
25 |
Correct |
4 ms |
2688 KB |
Output is correct |
26 |
Correct |
4 ms |
2688 KB |
Output is correct |
27 |
Correct |
4 ms |
2688 KB |
Output is correct |
28 |
Correct |
3 ms |
2688 KB |
Output is correct |
29 |
Correct |
4 ms |
2688 KB |
Output is correct |
30 |
Correct |
3 ms |
2688 KB |
Output is correct |
31 |
Correct |
3 ms |
2688 KB |
Output is correct |
32 |
Correct |
4 ms |
2688 KB |
Output is correct |
33 |
Correct |
3 ms |
2688 KB |
Output is correct |
34 |
Correct |
4 ms |
2688 KB |
Output is correct |
35 |
Correct |
4 ms |
2688 KB |
Output is correct |
36 |
Correct |
3 ms |
2688 KB |
Output is correct |
37 |
Correct |
4 ms |
2688 KB |
Output is correct |
38 |
Correct |
4 ms |
2688 KB |
Output is correct |
39 |
Correct |
282 ms |
27288 KB |
Output is correct |
40 |
Correct |
304 ms |
27384 KB |
Output is correct |
41 |
Correct |
141 ms |
18808 KB |
Output is correct |
42 |
Correct |
24 ms |
6400 KB |
Output is correct |
43 |
Correct |
4 ms |
2688 KB |
Output is correct |
44 |
Correct |
4 ms |
2688 KB |
Output is correct |
45 |
Correct |
4 ms |
2688 KB |
Output is correct |
46 |
Correct |
4 ms |
2688 KB |
Output is correct |
47 |
Correct |
4 ms |
2688 KB |
Output is correct |
48 |
Correct |
4 ms |
2688 KB |
Output is correct |
49 |
Correct |
4 ms |
2688 KB |
Output is correct |
50 |
Correct |
3 ms |
2688 KB |
Output is correct |
51 |
Correct |
4 ms |
2688 KB |
Output is correct |
52 |
Correct |
4 ms |
2688 KB |
Output is correct |
53 |
Correct |
4 ms |
2688 KB |
Output is correct |
54 |
Correct |
4 ms |
2688 KB |
Output is correct |
55 |
Correct |
4 ms |
2688 KB |
Output is correct |
56 |
Correct |
4 ms |
2816 KB |
Output is correct |
57 |
Correct |
333 ms |
20528 KB |
Output is correct |
58 |
Correct |
306 ms |
20472 KB |
Output is correct |
59 |
Correct |
345 ms |
20472 KB |
Output is correct |
60 |
Correct |
380 ms |
20700 KB |
Output is correct |
61 |
Correct |
341 ms |
20340 KB |
Output is correct |
62 |
Correct |
299 ms |
20344 KB |
Output is correct |
63 |
Correct |
311 ms |
20180 KB |
Output is correct |
64 |
Incorrect |
297 ms |
20164 KB |
Output isn't correct |
65 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
68 ms |
9340 KB |
Output is correct |
2 |
Correct |
72 ms |
9420 KB |
Output is correct |
3 |
Correct |
68 ms |
9464 KB |
Output is correct |
4 |
Correct |
72 ms |
9464 KB |
Output is correct |
5 |
Correct |
75 ms |
9408 KB |
Output is correct |
6 |
Correct |
85 ms |
10012 KB |
Output is correct |
7 |
Correct |
75 ms |
9720 KB |
Output is correct |
8 |
Correct |
70 ms |
9336 KB |
Output is correct |
9 |
Correct |
66 ms |
9204 KB |
Output is correct |
10 |
Correct |
77 ms |
9592 KB |
Output is correct |
11 |
Correct |
4 ms |
2660 KB |
Output is correct |
12 |
Correct |
7 ms |
3452 KB |
Output is correct |
13 |
Correct |
7 ms |
3584 KB |
Output is correct |
14 |
Correct |
7 ms |
3452 KB |
Output is correct |
15 |
Correct |
7 ms |
3456 KB |
Output is correct |
16 |
Correct |
7 ms |
3452 KB |
Output is correct |
17 |
Correct |
6 ms |
3452 KB |
Output is correct |
18 |
Correct |
8 ms |
3580 KB |
Output is correct |
19 |
Correct |
7 ms |
3452 KB |
Output is correct |
20 |
Correct |
4 ms |
2688 KB |
Output is correct |
21 |
Correct |
4 ms |
2688 KB |
Output is correct |
22 |
Correct |
4 ms |
2688 KB |
Output is correct |
23 |
Correct |
9 ms |
3452 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
262 ms |
27380 KB |
Output is correct |
2 |
Correct |
284 ms |
27248 KB |
Output is correct |
3 |
Correct |
159 ms |
18808 KB |
Output is correct |
4 |
Correct |
24 ms |
6400 KB |
Output is correct |
5 |
Correct |
23 ms |
4864 KB |
Output is correct |
6 |
Correct |
46 ms |
8164 KB |
Output is correct |
7 |
Correct |
4 ms |
2816 KB |
Output is correct |
8 |
Correct |
113 ms |
11864 KB |
Output is correct |
9 |
Correct |
161 ms |
15264 KB |
Output is correct |
10 |
Correct |
4 ms |
2816 KB |
Output is correct |
11 |
Correct |
230 ms |
19320 KB |
Output is correct |
12 |
Correct |
322 ms |
23416 KB |
Output is correct |
13 |
Correct |
5 ms |
2944 KB |
Output is correct |
14 |
Correct |
5 ms |
2816 KB |
Output is correct |
15 |
Correct |
5 ms |
2944 KB |
Output is correct |
16 |
Correct |
7 ms |
3200 KB |
Output is correct |
17 |
Correct |
4 ms |
2816 KB |
Output is correct |
18 |
Correct |
5 ms |
2944 KB |
Output is correct |
19 |
Correct |
7 ms |
3072 KB |
Output is correct |
20 |
Correct |
5 ms |
2816 KB |
Output is correct |
21 |
Correct |
6 ms |
3072 KB |
Output is correct |
22 |
Correct |
7 ms |
3200 KB |
Output is correct |
23 |
Correct |
4 ms |
2688 KB |
Output is correct |
24 |
Correct |
4 ms |
2688 KB |
Output is correct |
25 |
Correct |
4 ms |
2688 KB |
Output is correct |
26 |
Correct |
3 ms |
2688 KB |
Output is correct |
27 |
Correct |
4 ms |
2688 KB |
Output is correct |
28 |
Correct |
4 ms |
2688 KB |
Output is correct |
29 |
Correct |
4 ms |
2688 KB |
Output is correct |
30 |
Correct |
4 ms |
2688 KB |
Output is correct |
31 |
Correct |
4 ms |
2688 KB |
Output is correct |
32 |
Correct |
4 ms |
2688 KB |
Output is correct |
33 |
Correct |
3 ms |
2688 KB |
Output is correct |
34 |
Correct |
4 ms |
2688 KB |
Output is correct |
35 |
Correct |
4 ms |
2688 KB |
Output is correct |
36 |
Correct |
4 ms |
2688 KB |
Output is correct |
37 |
Correct |
4 ms |
2688 KB |
Output is correct |
38 |
Correct |
3 ms |
2688 KB |
Output is correct |
39 |
Correct |
4 ms |
2688 KB |
Output is correct |
40 |
Correct |
4 ms |
2688 KB |
Output is correct |
41 |
Correct |
3 ms |
2688 KB |
Output is correct |
42 |
Correct |
8 ms |
3456 KB |
Output is correct |
43 |
Correct |
8 ms |
3456 KB |
Output is correct |
44 |
Correct |
6 ms |
3072 KB |
Output is correct |
45 |
Correct |
5 ms |
2816 KB |
Output is correct |
46 |
Correct |
7 ms |
3200 KB |
Output is correct |
47 |
Correct |
7 ms |
3200 KB |
Output is correct |
48 |
Correct |
5 ms |
2944 KB |
Output is correct |
49 |
Correct |
4 ms |
2944 KB |
Output is correct |
50 |
Correct |
6 ms |
3200 KB |
Output is correct |
51 |
Correct |
8 ms |
3200 KB |
Output is correct |
52 |
Correct |
4 ms |
2816 KB |
Output is correct |
53 |
Correct |
5 ms |
3072 KB |
Output is correct |
54 |
Correct |
7 ms |
3200 KB |
Output is correct |
55 |
Correct |
7 ms |
3200 KB |
Output is correct |
56 |
Correct |
6 ms |
3072 KB |
Output is correct |
57 |
Correct |
6 ms |
3072 KB |
Output is correct |
58 |
Correct |
5 ms |
2944 KB |
Output is correct |
59 |
Correct |
5 ms |
2944 KB |
Output is correct |
60 |
Correct |
7 ms |
3200 KB |
Output is correct |
61 |
Correct |
8 ms |
3200 KB |
Output is correct |
62 |
Correct |
8 ms |
3200 KB |
Output is correct |
63 |
Correct |
7 ms |
3200 KB |
Output is correct |
64 |
Correct |
7 ms |
3200 KB |
Output is correct |
65 |
Correct |
7 ms |
3196 KB |
Output is correct |
66 |
Correct |
5 ms |
2944 KB |
Output is correct |
67 |
Correct |
6 ms |
2816 KB |
Output is correct |
68 |
Correct |
4 ms |
2816 KB |
Output is correct |
69 |
Correct |
4 ms |
2764 KB |
Output is correct |
70 |
Correct |
7 ms |
3200 KB |
Output is correct |
71 |
Correct |
7 ms |
3200 KB |
Output is correct |
72 |
Correct |
5 ms |
2944 KB |
Output is correct |
73 |
Correct |
4 ms |
2816 KB |
Output is correct |
74 |
Correct |
6 ms |
3072 KB |
Output is correct |
75 |
Correct |
8 ms |
3200 KB |
Output is correct |
76 |
Incorrect |
6 ms |
3072 KB |
Output isn't correct |
77 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
262 ms |
27380 KB |
Output is correct |
2 |
Correct |
284 ms |
27248 KB |
Output is correct |
3 |
Correct |
159 ms |
18808 KB |
Output is correct |
4 |
Correct |
24 ms |
6400 KB |
Output is correct |
5 |
Correct |
23 ms |
4864 KB |
Output is correct |
6 |
Correct |
46 ms |
8164 KB |
Output is correct |
7 |
Correct |
4 ms |
2816 KB |
Output is correct |
8 |
Correct |
113 ms |
11864 KB |
Output is correct |
9 |
Correct |
161 ms |
15264 KB |
Output is correct |
10 |
Correct |
4 ms |
2816 KB |
Output is correct |
11 |
Correct |
230 ms |
19320 KB |
Output is correct |
12 |
Correct |
322 ms |
23416 KB |
Output is correct |
13 |
Correct |
5 ms |
2944 KB |
Output is correct |
14 |
Correct |
4 ms |
2688 KB |
Output is correct |
15 |
Correct |
4 ms |
2688 KB |
Output is correct |
16 |
Correct |
4 ms |
2688 KB |
Output is correct |
17 |
Correct |
4 ms |
2732 KB |
Output is correct |
18 |
Correct |
4 ms |
2688 KB |
Output is correct |
19 |
Correct |
4 ms |
2688 KB |
Output is correct |
20 |
Correct |
4 ms |
2688 KB |
Output is correct |
21 |
Correct |
4 ms |
2688 KB |
Output is correct |
22 |
Correct |
4 ms |
2688 KB |
Output is correct |
23 |
Correct |
4 ms |
2688 KB |
Output is correct |
24 |
Correct |
4 ms |
2688 KB |
Output is correct |
25 |
Correct |
4 ms |
2688 KB |
Output is correct |
26 |
Correct |
4 ms |
2688 KB |
Output is correct |
27 |
Correct |
4 ms |
2688 KB |
Output is correct |
28 |
Correct |
3 ms |
2688 KB |
Output is correct |
29 |
Correct |
4 ms |
2688 KB |
Output is correct |
30 |
Correct |
3 ms |
2688 KB |
Output is correct |
31 |
Correct |
3 ms |
2688 KB |
Output is correct |
32 |
Correct |
4 ms |
2688 KB |
Output is correct |
33 |
Correct |
3 ms |
2688 KB |
Output is correct |
34 |
Correct |
4 ms |
2688 KB |
Output is correct |
35 |
Correct |
4 ms |
2688 KB |
Output is correct |
36 |
Correct |
3 ms |
2688 KB |
Output is correct |
37 |
Correct |
4 ms |
2688 KB |
Output is correct |
38 |
Correct |
4 ms |
2688 KB |
Output is correct |
39 |
Correct |
282 ms |
27288 KB |
Output is correct |
40 |
Correct |
304 ms |
27384 KB |
Output is correct |
41 |
Correct |
141 ms |
18808 KB |
Output is correct |
42 |
Correct |
24 ms |
6400 KB |
Output is correct |
43 |
Correct |
4 ms |
2688 KB |
Output is correct |
44 |
Correct |
4 ms |
2688 KB |
Output is correct |
45 |
Correct |
4 ms |
2688 KB |
Output is correct |
46 |
Correct |
4 ms |
2688 KB |
Output is correct |
47 |
Correct |
4 ms |
2688 KB |
Output is correct |
48 |
Correct |
4 ms |
2688 KB |
Output is correct |
49 |
Correct |
4 ms |
2688 KB |
Output is correct |
50 |
Correct |
3 ms |
2688 KB |
Output is correct |
51 |
Correct |
4 ms |
2688 KB |
Output is correct |
52 |
Correct |
4 ms |
2688 KB |
Output is correct |
53 |
Correct |
4 ms |
2688 KB |
Output is correct |
54 |
Correct |
4 ms |
2688 KB |
Output is correct |
55 |
Correct |
4 ms |
2688 KB |
Output is correct |
56 |
Correct |
4 ms |
2816 KB |
Output is correct |
57 |
Correct |
333 ms |
20528 KB |
Output is correct |
58 |
Correct |
306 ms |
20472 KB |
Output is correct |
59 |
Correct |
345 ms |
20472 KB |
Output is correct |
60 |
Correct |
380 ms |
20700 KB |
Output is correct |
61 |
Correct |
341 ms |
20340 KB |
Output is correct |
62 |
Correct |
299 ms |
20344 KB |
Output is correct |
63 |
Correct |
311 ms |
20180 KB |
Output is correct |
64 |
Incorrect |
297 ms |
20164 KB |
Output isn't correct |
65 |
Halted |
0 ms |
0 KB |
- |