#include "dreaming.h"
#include<vector>
#include<iostream>
#include<algorithm>
using namespace std;
vector<pair<int,int > > g[200000];
int u[200000],x[200000],d[200000],pa[200000],mh,ind,t,pat;
void dfs(int v,int p)
{
u[v]=1;
for(int i=0;i<g[v].size();i++)
{
int to =g[v][i].first;
int her=g[v][i].second;
if(to==p)
continue;
d[to]=d[v]+ her;
pa[to]=v;
if(d[to]>mh)
{
mh=d[to];
ind=to;
}
dfs(to,v);
}
}
int travelTime(int N, int M, int L, int A[], int B[], int T[]) {
for(int i=0;i<M;i++)
{
g[A[i]].push_back(make_pair(B[i],T[i]));
g[B[i]].push_back(make_pair(A[i],T[i]));
}
for(int i=0;i<N;i++)
{
if(u[i]==0)
{
d[i]=0;
mh=0;
ind=i;
dfs(i,-1);
int a=ind;
d[a]=0;
mh=0;
ind=a;
dfs(a,-1);
int b=ind;
int e=b;
int l=mh;
while(e!=a)
{
l=min(l,max(mh-d[e],d[e]));
e=pa[e];
}
x[t]=l;
t++;
}
}
sort(x,x+t);
pat=max(pat,x[t-1]);
if(t>=2)
pat=max(pat,x[t-1]+x[t-2]+L);
if(t>=3)
pat=max(pat,x[t-2]+x[t-3]+2*L);
return pat;
}
Compilation message
dreaming.cpp: In function 'void dfs(int, int)':
dreaming.cpp:11:18: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int i=0;i<g[v].size();i++)
~^~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
65 ms |
14328 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
65 ms |
14328 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
65 ms |
14328 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
29 ms |
8696 KB |
Output is correct |
2 |
Correct |
31 ms |
8704 KB |
Output is correct |
3 |
Correct |
31 ms |
8668 KB |
Output is correct |
4 |
Correct |
34 ms |
8696 KB |
Output is correct |
5 |
Correct |
33 ms |
8696 KB |
Output is correct |
6 |
Correct |
32 ms |
8960 KB |
Output is correct |
7 |
Correct |
35 ms |
8952 KB |
Output is correct |
8 |
Correct |
33 ms |
8676 KB |
Output is correct |
9 |
Correct |
35 ms |
8568 KB |
Output is correct |
10 |
Correct |
33 ms |
8832 KB |
Output is correct |
11 |
Correct |
6 ms |
5120 KB |
Output is correct |
12 |
Correct |
9 ms |
6656 KB |
Output is correct |
13 |
Correct |
10 ms |
6656 KB |
Output is correct |
14 |
Correct |
9 ms |
6656 KB |
Output is correct |
15 |
Correct |
10 ms |
6656 KB |
Output is correct |
16 |
Correct |
9 ms |
6656 KB |
Output is correct |
17 |
Correct |
10 ms |
6400 KB |
Output is correct |
18 |
Correct |
10 ms |
6656 KB |
Output is correct |
19 |
Correct |
9 ms |
6656 KB |
Output is correct |
20 |
Correct |
6 ms |
5120 KB |
Output is correct |
21 |
Correct |
6 ms |
5120 KB |
Output is correct |
22 |
Correct |
6 ms |
5120 KB |
Output is correct |
23 |
Correct |
10 ms |
6656 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
65 ms |
14328 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
65 ms |
14328 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |