#include "dreaming.h"
#include <cstdio>
#include <algorithm>
#include <vector>
using namespace std;
typedef pair<int,int> pp;
typedef vector<pp> vec;
typedef vector<vec> mat;
#define pb push_back
int N;
int subsz[100000],subsz2[100000];
int vi[100000],vi2[100000];
int Max,len[100000],ans;
bool chk[100000];
vec s;
mat path;
void dfs(int v){
chk[v]=1;
for(int i=0;i<path[v].size();i++){
int u=path[v][i].first;
int c=path[v][i].second;
if(chk[u])continue;
dfs(u);
int t=subsz[u]+c;
if(subsz[v]<t){
subsz2[v]=subsz[v];vi2[v]=vi[v];
subsz[v]=t;vi[v]=u;
}else if(subsz2[v]<t){
subsz2[v]=t;vi2[v]=u;
}
}
// printf("%d : (%d,%d), (%d,%d)\n",v,subsz[v],vi[v],subsz2[v],vi2[v]);
}
void dfs2(int v,int h){
Max=min(Max,max(h,max(subsz[v],subsz2[v])));
ans=max(ans,max(h+subsz[v],subsz[v]+subsz2[v]));
chk[v]=0;
for(int i=0;i<path[v].size();i++){
int u=path[v][i].first;
int c=path[v][i].second;
if(!chk[u])continue;
if(u==vi[v]){
dfs2(u,max(h,subsz2[v])+c);
}else if(u==vi2[v]){
dfs2(u,max(h,subsz[v])+c);
}
}
}
int travelTime(int N_, int M, int L, int A[], int B[], int T[]) {
N=N_;
path.assign(N+1,vec());
for(int i=0;i<M;i++){
path[A[i]].pb(pp(B[i],T[i]));
path[B[i]].pb(pp(A[i],T[i]));
}
for(int i=0;i<N;i++){
if(!chk[i]){
dfs(i);
}
}
for(int i=0;i<N;i++){
if(chk[i]){
Max=1e9;
dfs2(i,0);
len[i]=Max;
s.pb(pp(len[i],i));
}
}
sort(s.begin(),s.end());
/*
for(int i=0;i<s.size();i++){
printf("(%d,%d) ",s[i].first,s[i].second);
}
*/
if(s.size()==1)return max(ans,s[0].first);
return max(ans,s[s.size()-1].first+s[s.size()-2].first+L);
}
Compilation message
dreaming.cpp: In function 'void dfs(int)':
dreaming.cpp:21:15: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int i=0;i<path[v].size();i++){
~^~~~~~~~~~~~~~~
dreaming.cpp: In function 'void dfs2(int, int)':
dreaming.cpp:41:15: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int i=0;i<path[v].size();i++){
~^~~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
57 ms |
11000 KB |
Output is correct |
2 |
Correct |
57 ms |
10872 KB |
Output is correct |
3 |
Correct |
41 ms |
8572 KB |
Output is correct |
4 |
Correct |
9 ms |
1920 KB |
Output is correct |
5 |
Correct |
8 ms |
1408 KB |
Output is correct |
6 |
Correct |
14 ms |
2688 KB |
Output is correct |
7 |
Correct |
2 ms |
384 KB |
Output is correct |
8 |
Correct |
28 ms |
4864 KB |
Output is correct |
9 |
Correct |
37 ms |
6904 KB |
Output is correct |
10 |
Correct |
3 ms |
512 KB |
Output is correct |
11 |
Correct |
49 ms |
8312 KB |
Output is correct |
12 |
Correct |
60 ms |
9588 KB |
Output is correct |
13 |
Correct |
2 ms |
384 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
57 ms |
11000 KB |
Output is correct |
2 |
Correct |
57 ms |
10872 KB |
Output is correct |
3 |
Correct |
41 ms |
8572 KB |
Output is correct |
4 |
Correct |
9 ms |
1920 KB |
Output is correct |
5 |
Correct |
8 ms |
1408 KB |
Output is correct |
6 |
Correct |
14 ms |
2688 KB |
Output is correct |
7 |
Correct |
2 ms |
384 KB |
Output is correct |
8 |
Correct |
28 ms |
4864 KB |
Output is correct |
9 |
Correct |
37 ms |
6904 KB |
Output is correct |
10 |
Correct |
3 ms |
512 KB |
Output is correct |
11 |
Correct |
49 ms |
8312 KB |
Output is correct |
12 |
Correct |
60 ms |
9588 KB |
Output is correct |
13 |
Correct |
2 ms |
384 KB |
Output is correct |
14 |
Correct |
2 ms |
384 KB |
Output is correct |
15 |
Correct |
2 ms |
384 KB |
Output is correct |
16 |
Correct |
2 ms |
384 KB |
Output is correct |
17 |
Correct |
2 ms |
384 KB |
Output is correct |
18 |
Correct |
2 ms |
384 KB |
Output is correct |
19 |
Correct |
2 ms |
384 KB |
Output is correct |
20 |
Correct |
2 ms |
384 KB |
Output is correct |
21 |
Correct |
2 ms |
384 KB |
Output is correct |
22 |
Correct |
2 ms |
384 KB |
Output is correct |
23 |
Correct |
2 ms |
384 KB |
Output is correct |
24 |
Correct |
2 ms |
384 KB |
Output is correct |
25 |
Correct |
2 ms |
384 KB |
Output is correct |
26 |
Correct |
2 ms |
384 KB |
Output is correct |
27 |
Correct |
2 ms |
384 KB |
Output is correct |
28 |
Correct |
2 ms |
384 KB |
Output is correct |
29 |
Correct |
2 ms |
384 KB |
Output is correct |
30 |
Incorrect |
2 ms |
384 KB |
Output isn't correct |
31 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
57 ms |
11000 KB |
Output is correct |
2 |
Correct |
57 ms |
10872 KB |
Output is correct |
3 |
Correct |
41 ms |
8572 KB |
Output is correct |
4 |
Correct |
9 ms |
1920 KB |
Output is correct |
5 |
Correct |
8 ms |
1408 KB |
Output is correct |
6 |
Correct |
14 ms |
2688 KB |
Output is correct |
7 |
Correct |
2 ms |
384 KB |
Output is correct |
8 |
Correct |
28 ms |
4864 KB |
Output is correct |
9 |
Correct |
37 ms |
6904 KB |
Output is correct |
10 |
Correct |
3 ms |
512 KB |
Output is correct |
11 |
Correct |
49 ms |
8312 KB |
Output is correct |
12 |
Correct |
60 ms |
9588 KB |
Output is correct |
13 |
Correct |
2 ms |
384 KB |
Output is correct |
14 |
Correct |
2 ms |
384 KB |
Output is correct |
15 |
Correct |
2 ms |
384 KB |
Output is correct |
16 |
Correct |
2 ms |
384 KB |
Output is correct |
17 |
Correct |
2 ms |
384 KB |
Output is correct |
18 |
Correct |
2 ms |
384 KB |
Output is correct |
19 |
Correct |
2 ms |
384 KB |
Output is correct |
20 |
Correct |
2 ms |
384 KB |
Output is correct |
21 |
Correct |
2 ms |
384 KB |
Output is correct |
22 |
Correct |
2 ms |
384 KB |
Output is correct |
23 |
Correct |
2 ms |
384 KB |
Output is correct |
24 |
Correct |
2 ms |
384 KB |
Output is correct |
25 |
Correct |
2 ms |
384 KB |
Output is correct |
26 |
Correct |
2 ms |
384 KB |
Output is correct |
27 |
Correct |
2 ms |
384 KB |
Output is correct |
28 |
Correct |
2 ms |
384 KB |
Output is correct |
29 |
Correct |
2 ms |
384 KB |
Output is correct |
30 |
Incorrect |
2 ms |
384 KB |
Output isn't correct |
31 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
34 ms |
7420 KB |
Output is correct |
2 |
Incorrect |
36 ms |
7392 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
57 ms |
11000 KB |
Output is correct |
2 |
Correct |
57 ms |
10872 KB |
Output is correct |
3 |
Correct |
41 ms |
8572 KB |
Output is correct |
4 |
Correct |
9 ms |
1920 KB |
Output is correct |
5 |
Correct |
8 ms |
1408 KB |
Output is correct |
6 |
Correct |
14 ms |
2688 KB |
Output is correct |
7 |
Correct |
2 ms |
384 KB |
Output is correct |
8 |
Correct |
28 ms |
4864 KB |
Output is correct |
9 |
Correct |
37 ms |
6904 KB |
Output is correct |
10 |
Correct |
3 ms |
512 KB |
Output is correct |
11 |
Correct |
49 ms |
8312 KB |
Output is correct |
12 |
Correct |
60 ms |
9588 KB |
Output is correct |
13 |
Correct |
2 ms |
384 KB |
Output is correct |
14 |
Correct |
2 ms |
384 KB |
Output is correct |
15 |
Correct |
3 ms |
512 KB |
Output is correct |
16 |
Correct |
4 ms |
640 KB |
Output is correct |
17 |
Correct |
2 ms |
512 KB |
Output is correct |
18 |
Correct |
3 ms |
512 KB |
Output is correct |
19 |
Correct |
4 ms |
640 KB |
Output is correct |
20 |
Incorrect |
2 ms |
512 KB |
Output isn't correct |
21 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
57 ms |
11000 KB |
Output is correct |
2 |
Correct |
57 ms |
10872 KB |
Output is correct |
3 |
Correct |
41 ms |
8572 KB |
Output is correct |
4 |
Correct |
9 ms |
1920 KB |
Output is correct |
5 |
Correct |
8 ms |
1408 KB |
Output is correct |
6 |
Correct |
14 ms |
2688 KB |
Output is correct |
7 |
Correct |
2 ms |
384 KB |
Output is correct |
8 |
Correct |
28 ms |
4864 KB |
Output is correct |
9 |
Correct |
37 ms |
6904 KB |
Output is correct |
10 |
Correct |
3 ms |
512 KB |
Output is correct |
11 |
Correct |
49 ms |
8312 KB |
Output is correct |
12 |
Correct |
60 ms |
9588 KB |
Output is correct |
13 |
Correct |
2 ms |
384 KB |
Output is correct |
14 |
Correct |
2 ms |
384 KB |
Output is correct |
15 |
Correct |
2 ms |
384 KB |
Output is correct |
16 |
Correct |
2 ms |
384 KB |
Output is correct |
17 |
Correct |
2 ms |
384 KB |
Output is correct |
18 |
Correct |
2 ms |
384 KB |
Output is correct |
19 |
Correct |
2 ms |
384 KB |
Output is correct |
20 |
Correct |
2 ms |
384 KB |
Output is correct |
21 |
Correct |
2 ms |
384 KB |
Output is correct |
22 |
Correct |
2 ms |
384 KB |
Output is correct |
23 |
Correct |
2 ms |
384 KB |
Output is correct |
24 |
Correct |
2 ms |
384 KB |
Output is correct |
25 |
Correct |
2 ms |
384 KB |
Output is correct |
26 |
Correct |
2 ms |
384 KB |
Output is correct |
27 |
Correct |
2 ms |
384 KB |
Output is correct |
28 |
Correct |
2 ms |
384 KB |
Output is correct |
29 |
Correct |
2 ms |
384 KB |
Output is correct |
30 |
Incorrect |
2 ms |
384 KB |
Output isn't correct |
31 |
Halted |
0 ms |
0 KB |
- |