#include <bits/stdc++.h>
using namespace std;
#include "dreaming.h"
#define pb push_back
#define mp make_pair
#define st first
#define nd second
#define NN 100005
vector < pair<int,int> > V[NN];
int H[NN],M[NN],node[NN],M2[NN],mn,ss;
void f(int x){
H[x] = 1;
int t;
for(int i=0; i<V[x].size(); i++){
if(H[ V[x][i].st ]) continue;
f(V[x][i].st);
t = M[ V[x][i].st ] + V[x][i].nd;
if(M[x] < t) { M2[x] = M[x]; M[x] = t; node[x] = V[x][i].st; }
else if(M2[x] < t) M2[x] = t;
}
ss = max(ss , M[x] + M2[x]);
}
void g(int x, int p, int t){
mn = min(mn , max(M[x] , t));
for(int i=0; i<V[x].size(); i++){
if(V[x][i].st == p) continue;
int a = max(t , node[x] == V[x][i].st ? M2[x] : M[x]);
g(V[x][i].st , x , a + V[x][i].nd);
}
}
int travelTime(int n, int m, int l, int *A, int *B, int *T){
int t,i,x=0;
for(i=0;i<m;i++){
V[ A[i] ].pb(mp(B[i],T[i]));
V[ B[i] ].pb(mp(A[i],T[i]));
}
for(i=0;i<n;i++){
if(H[i]) continue;
mn = 1e9;
f(i);
g(i,-1,0);
//cout << i << " " << x << " " << mn << " ss\n";
ss = max(ss , x + mn + l);
x = min(max(mn , x+l) , max(x , mn+l));
}
return ss;
}
Compilation message
dreaming.cpp: In function 'void f(int)':
dreaming.cpp:17:19: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int i=0; i<V[x].size(); i++){
~^~~~~~~~~~~~
dreaming.cpp: In function 'void g(int, int, int)':
dreaming.cpp:28:19: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int i=0; i<V[x].size(); i++){
~^~~~~~~~~~~~
dreaming.cpp: In function 'int travelTime(int, int, int, int*, int*, int*)':
dreaming.cpp:36:9: warning: unused variable 't' [-Wunused-variable]
int t,i,x=0;
^
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
69 ms |
12024 KB |
Output is correct |
2 |
Correct |
61 ms |
11768 KB |
Output is correct |
3 |
Correct |
46 ms |
10232 KB |
Output is correct |
4 |
Correct |
11 ms |
4096 KB |
Output is correct |
5 |
Correct |
9 ms |
3456 KB |
Output is correct |
6 |
Correct |
16 ms |
4728 KB |
Output is correct |
7 |
Incorrect |
4 ms |
2816 KB |
Output isn't correct |
8 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
69 ms |
12024 KB |
Output is correct |
2 |
Correct |
61 ms |
11768 KB |
Output is correct |
3 |
Correct |
46 ms |
10232 KB |
Output is correct |
4 |
Correct |
11 ms |
4096 KB |
Output is correct |
5 |
Correct |
9 ms |
3456 KB |
Output is correct |
6 |
Correct |
16 ms |
4728 KB |
Output is correct |
7 |
Incorrect |
4 ms |
2816 KB |
Output isn't correct |
8 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
69 ms |
12024 KB |
Output is correct |
2 |
Correct |
61 ms |
11768 KB |
Output is correct |
3 |
Correct |
46 ms |
10232 KB |
Output is correct |
4 |
Correct |
11 ms |
4096 KB |
Output is correct |
5 |
Correct |
9 ms |
3456 KB |
Output is correct |
6 |
Correct |
16 ms |
4728 KB |
Output is correct |
7 |
Incorrect |
4 ms |
2816 KB |
Output isn't correct |
8 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
26 ms |
6408 KB |
Output is correct |
2 |
Incorrect |
31 ms |
6512 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
69 ms |
12024 KB |
Output is correct |
2 |
Correct |
61 ms |
11768 KB |
Output is correct |
3 |
Correct |
46 ms |
10232 KB |
Output is correct |
4 |
Correct |
11 ms |
4096 KB |
Output is correct |
5 |
Correct |
9 ms |
3456 KB |
Output is correct |
6 |
Correct |
16 ms |
4728 KB |
Output is correct |
7 |
Incorrect |
4 ms |
2816 KB |
Output isn't correct |
8 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
69 ms |
12024 KB |
Output is correct |
2 |
Correct |
61 ms |
11768 KB |
Output is correct |
3 |
Correct |
46 ms |
10232 KB |
Output is correct |
4 |
Correct |
11 ms |
4096 KB |
Output is correct |
5 |
Correct |
9 ms |
3456 KB |
Output is correct |
6 |
Correct |
16 ms |
4728 KB |
Output is correct |
7 |
Incorrect |
4 ms |
2816 KB |
Output isn't correct |
8 |
Halted |
0 ms |
0 KB |
- |