#include "dreaming.h"
#include <iostream>
#include <vector>
using namespace std;
const int nmax=100005;
vector< pair<int,int> > v[nmax];
vector<int> centr;
int d[nmax],viz[nmax],rep[nmax];
int far,root,n,nr,i,x,mx,mn,ans;
void dfs(int x)
{
int nod=0;
viz[x]=1;rep[++nr]=x;
for(int i=0;i<v[x].size();i++)
{
nod=v[x][i].first;
if(!viz[nod])
{
d[nod]=d[x]+v[x][i].second;
dfs(nod);
}
}
}
void get_diam()
{
far=root;nr=0;
dfs(root);
for(i=1;i<=nr;i++)
{
x=rep[i];
if(d[x]>d[far])
far=x;
viz[x]=0;
}
nr=0;d[far]=0;
dfs(far);mx=0;
for(i=1;i<=nr;i++)
{
x=rep[i];
mx=max(d[x],mx);
}
mn=(1<<30);
for(i=1;i<=nr;i++)
{
x=rep[i];
if(max(d[x],mx-d[x])<mn)
mn=max(d[x],mx-d[x]);
}
centr.push_back(mn);
}
int travelTime(int N, int M, int L, int A[], int B[], int T[]) {
n=N;
for(i=0;i<M;i++)
{
v[A[i]].push_back({B[i],T[i]});
v[B[i]].push_back({A[i],T[i]});
}
for(root=1;root<=n;root++)
if(!viz[root])
get_diam();
for(i=0;i<centr.size();i++)
{
ans+=centr[i];
if(i+1<centr.size())
ans+=L;
}
return ans;
}
Compilation message
dreaming.cpp: In function 'void dfs(int)':
dreaming.cpp:14:18: 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:61:14: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(i=0;i<centr.size();i++)
~^~~~~~~~~~~~~
dreaming.cpp:64:15: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
if(i+1<centr.size())
~~~^~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
57 ms |
10488 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
57 ms |
10488 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
57 ms |
10488 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
31 ms |
6144 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
57 ms |
10488 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
57 ms |
10488 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |