#include "dreaming.h"
#include "bits/stdc++.h"
using namespace std;
typedef pair<int,int> pii;
const int MAXN=100005;
vector<pii> adj[MAXN];
vector<int> kel[MAXN];
int par[MAXN];
int find(int x){
if(par[x]==x)return x;
return par[x]=find(par[x]);
}
void join(int a,int b){
par[find(a)]=find(b);
}
int jarak;
void dfs(int now,int par,int dist){
jarak=max(jarak,dist);
for(auto nxt : adj[now]){
if(nxt.first==par)continue;
dfs(nxt.first,now,dist+nxt.second);
}
}
int travelTime(int N, int M, int L, int A[], int B[], int T[]) {
assert(M==N-2);
for(int i=1;i<=N;i++){
par[i]=i;
adj[i].clear();
kel[i].clear();
}
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]});
join(A[i],B[i]);
}
for(int i=1;i<=N;i++)kel[find(i)].push_back(i);
vector<int> v;
int ans=0,tot=0;
for(int i=1;i<=N;i++){
//for every tree, find root s.t the distance between the root and the furthest leaf is minimum
tot+=i;
if(kel[i].empty())continue;
int furthest=1e9,diameter=0;
for(int j=0;j<(int)kel[i].size();j++){
jarak=0;
dfs(kel[i][j],-1,0);
furthest=min(furthest,jarak);
diameter=max(diameter,jarak);
}
v.push_back(furthest);
ans=max(ans,diameter);
}
assert(tot==(N*(N+1))/2);
if(v.size()==2)ans=max(ans,v[0]+v[1]+L);
// else assert(0);
return ans;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1088 ms |
14188 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1088 ms |
14188 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1088 ms |
14188 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
21 ms |
10732 KB |
Execution killed with signal 6 (could be triggered by violating memory limits) |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1088 ms |
14188 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1088 ms |
14188 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |