#include"dreaming.h"
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
int n,m,l;
vector<pair<int,int>>nodes[100000];
bool vis[100000];
vector<int>node_list;
void dfs(int node){
if(vis[node])
return;
vis[node]=true;
node_list.push_back(node);
for(auto ne:nodes[node])
dfs(ne.first);
}
int get_max_dist(int node,int prev){
int res=0;
for(auto ne:nodes[node]){
if(ne.first==prev)
continue;
res=max(res,get_max_dist(ne.first,node)+ne.second);
}
return res;
}
int get_diameter(int root){
node_list.clear();
dfs(root);
int res=2e9;
for(int node:node_list){
res=min(res,get_max_dist(node,node));
}
return 0;
}
int travelTime(int N,int M,int L,int A[],int B[],int T[]){
n=N;
m=M;
l=L;
for(int i=0;i<m;i++){
nodes[A[i]].emplace_back(B[i],T[i]);
nodes[B[i]].emplace_back(A[i],T[i]);
}
vector<int>dists;
cout<<n<<endl;
for(int i=0;i<n;i++){
if(!vis[i]){
dists.push_back(get_diameter(i));
}
}
sort(dists.begin(),dists.end());
reverse(dists.begin(),dists.end());
if(dists.size()==1)
return dists[0];
else
return dists[0]+dists[1]+l;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1067 ms |
9952 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
3672 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1067 ms |
9952 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
14 ms |
6236 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
3672 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1067 ms |
9952 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |