#include <bits/stdc++.h>
#include "dreaming.h"
using namespace std;
int n,vs[100002],fa[100002],d[100002];
typedef pair <int,int> pp;
vector <pp> adj[100002];
vector <int> X;
void dfs(int u)
{
vs[u]=1;
X.push_back(u);
for (int i=0;i<adj[u].size();i++)
{
int v=adj[u][i].first;
if (vs[v]==1) continue;
vs[v]=1;fa[v]=u;
d[v]=d[u]+adj[u][i].second;
dfs(v);
}
}
int get(int r)
{
X.clear();
dfs(r);
int p=r;
for (int i=0;i<X.size();i++)
{
if (d[X[i]]>d[p]) p=X[i];
vs[X[i]]=0;
}
X.clear();
r=p;fa[r]=0;d[r]=0;dfs(p);
for (int i=0;i<X.size();i++)
if (d[X[i]]>d[p]) p=X[i];
int ans=d[p];int w=d[p];
while (p>0)
{
ans=min(ans,max(d[p],w-d[p]));
p=fa[p];
}
return ans;
}
int travelTime(int nn,int m,int l,int A[],int B[],int T[])
{
n=nn;
for (int i=0;i<m;i++)
{
A[i]++;B[i]++;
adj[A[i]].push_back({B[i],T[i]});
adj[B[i]].push_back({A[i],T[i]});
}
vector <int> P;
for (int i=1;i<=n;i++)
{
if (vs[i]==1) continue;
int t=get(i);
// cout<<i-1<<' '<<t<<'\n';
P.push_back(t);
}
sort(P.begin(),P.end(),greater<int>());
if (P.size()==1) return P[0];
if (P.size()==2) return P[0]+P[1]+l;
return max(P[0]+P[1]+l,P[1]+P[2]+2*l);
}
Compilation message
dreaming.cpp: In function 'void dfs(int)':
dreaming.cpp:12:19: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for (int i=0;i<adj[u].size();i++)
~^~~~~~~~~~~~~~
dreaming.cpp: In function 'int get(int)':
dreaming.cpp:26:19: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for (int i=0;i<X.size();i++)
~^~~~~~~~~
dreaming.cpp:33:19: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for (int i=0;i<X.size();i++)
~^~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
79 ms |
12276 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
79 ms |
12276 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
79 ms |
12276 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
29 ms |
6912 KB |
Output is correct |
2 |
Correct |
24 ms |
6904 KB |
Output is correct |
3 |
Correct |
33 ms |
6904 KB |
Output is correct |
4 |
Correct |
25 ms |
6912 KB |
Output is correct |
5 |
Correct |
25 ms |
7040 KB |
Output is correct |
6 |
Correct |
26 ms |
7416 KB |
Output is correct |
7 |
Correct |
27 ms |
7032 KB |
Output is correct |
8 |
Correct |
27 ms |
6904 KB |
Output is correct |
9 |
Correct |
28 ms |
6776 KB |
Output is correct |
10 |
Correct |
26 ms |
7040 KB |
Output is correct |
11 |
Correct |
2 ms |
2688 KB |
Output is correct |
12 |
Correct |
6 ms |
4476 KB |
Output is correct |
13 |
Correct |
7 ms |
4604 KB |
Output is correct |
14 |
Correct |
7 ms |
4476 KB |
Output is correct |
15 |
Correct |
6 ms |
4476 KB |
Output is correct |
16 |
Correct |
8 ms |
4476 KB |
Output is correct |
17 |
Correct |
6 ms |
4348 KB |
Output is correct |
18 |
Correct |
7 ms |
4604 KB |
Output is correct |
19 |
Correct |
7 ms |
4604 KB |
Output is correct |
20 |
Correct |
2 ms |
2688 KB |
Output is correct |
21 |
Correct |
2 ms |
2688 KB |
Output is correct |
22 |
Correct |
2 ms |
2816 KB |
Output is correct |
23 |
Correct |
7 ms |
4476 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
79 ms |
12276 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
79 ms |
12276 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |