#include "dreaming.h"
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define pii pair<int,int>
const int maxn=1e5;
vector<pii> adj[maxn];
int d[maxn][2],d2[maxn],d3[maxn];
bool vis[maxn];
void dfs(int v,int p){
vis[v]=1;
vector<int> z;
for(auto [i,x]:adj[v])if(i!=p){
dfs(i,v);
z.pb(d[i][0]+x);
}
sort(z.rbegin(),z.rend());
for(int i=0;i<z.size()&&i<2;i++)d[v][i]=z[i];
}
void dfs2(int v,int p,int r){
d3[r]=min(d3[r],max(d[v][0],d2[v]));
for(auto [i,x]:adj[v])if(i!=p){
if(d[v][0]==d[i][0]+x){
d2[i]=x+max(d[v][1],d2[v]);
}else{
d2[i]=x+max(d[v][0],d2[v]);
}
dfs2(i,v,r);
}
}
int travelTime(int n, int m, int l, int a[], int b[], int t[]) {
for(int i=0;i<m;i++){
adj[a[i]].pb({b[i],t[i]});
adj[b[i]].pb({a[i],t[i]});
}
vector<int> v;
for(int i=0;i<n;i++){
if(!vis[i]){
dfs(i,-1);
d3[i]=1e9;
dfs2(i,-1,i);
v.pb(d3[i]);
}
}
sort(v.rbegin(),v.rend());
if(v.size()==1){
return v[0];
}else if(v.size()==2){
return v[0]+v[1]+l;
}else{
return max(v[0],v[2]+l)+v[1]+l;
}
}
Compilation message
dreaming.cpp: In function 'void dfs(int, int)':
dreaming.cpp:21:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
21 | for(int i=0;i<z.size()&&i<2;i++)d[v][i]=z[i];
| ~^~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
32 ms |
16168 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
2 ms |
5208 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
32 ms |
16168 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
14 ms |
8248 KB |
Output is correct |
2 |
Correct |
12 ms |
8284 KB |
Output is correct |
3 |
Correct |
13 ms |
8280 KB |
Output is correct |
4 |
Correct |
16 ms |
8280 KB |
Output is correct |
5 |
Correct |
12 ms |
8280 KB |
Output is correct |
6 |
Correct |
16 ms |
8672 KB |
Output is correct |
7 |
Correct |
17 ms |
8416 KB |
Output is correct |
8 |
Correct |
13 ms |
8276 KB |
Output is correct |
9 |
Correct |
13 ms |
8280 KB |
Output is correct |
10 |
Correct |
13 ms |
8404 KB |
Output is correct |
11 |
Correct |
1 ms |
5212 KB |
Output is correct |
12 |
Correct |
3 ms |
6104 KB |
Output is correct |
13 |
Correct |
3 ms |
6104 KB |
Output is correct |
14 |
Correct |
3 ms |
6104 KB |
Output is correct |
15 |
Correct |
3 ms |
6104 KB |
Output is correct |
16 |
Correct |
3 ms |
6100 KB |
Output is correct |
17 |
Correct |
3 ms |
6100 KB |
Output is correct |
18 |
Correct |
3 ms |
6104 KB |
Output is correct |
19 |
Correct |
4 ms |
6192 KB |
Output is correct |
20 |
Correct |
1 ms |
3160 KB |
Output is correct |
21 |
Correct |
1 ms |
3164 KB |
Output is correct |
22 |
Correct |
1 ms |
5468 KB |
Output is correct |
23 |
Correct |
3 ms |
6100 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
2 ms |
5208 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
32 ms |
16168 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |