#include <stdio.h>
#include <stdlib.h>
#include "dreaming.h"
#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define eb emplace_back
#define all(x) x.begin(),x.end()
#define sz(x) int(x.size())
#define MAX_N 100005
using ii = pair<int,int>;
vector<ii>adj[MAX_N];
vector<bool>vis(MAX_N);
int dist[MAX_N][2];
vector<int>nodes;
void dfs(int u, int p, int d, bool bit){
nodes.eb(u);
dist[u][bit]=d;
for(ii x:adj[u]){
int v=x.fi;
int t=x.se;
if(v==p)continue;
dfs(v,u,d+t,bit);
}
return;
}
int travelTime(int n, int m, int k, int a[], int b[], int t[]) {
for(int i=0; i<m; i++){
adj[a[i]].eb(b[i],t[i]);
adj[b[i]].eb(a[i],t[i]);
}
int ans = 0;
vector<int>answer;
for(int i=0; i<n; i++){
if(vis[i])continue;
dfs(i,-1,0,0);
int u=i; //farthestleaf
for(int x:nodes){
if(dist[x][0]>dist[u][0])u=x;
}
nodes=vector<int>();
dfs(u,-1,0,0);
int v=u; //farthest leaf
for(int x:nodes){
if(dist[x][0]>dist[v][0])v=x;
}
nodes=vector<int>();
dfs(v,-1,0,1);
//current max
ans = max(ans,dist[u][1]);
//current min
int res = 1e9;
for(int x:nodes){
res = min(res,max(dist[x][0],dist[x][1]));
}
answer.eb(res);
}
sort(all(answer),greater<int>());
if(sz(answer)>=2)ans = max(ans,answer[0]+answer[1]+k);
if(sz(answer)>=3)ans = max(ans,answer[1]+answer[2]+2*k);
return ans;
}
/*
int main() {
int N, M, L, i,res;
res = scanf("%d%d%d", &N, &M, &L);
cerr<<N<<" "<<M<<" "<<L<<" checking \n";
for (i = 0; i < M; i++)
res = scanf("%d%d%d", &A[i], &B[i], &T[i]);
int answer = travelTime(N, M, L, A, B, T);
printf("%d\n", answer);
return 0;
}
*/
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
1087 ms |
16452 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
1087 ms |
16452 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
1087 ms |
16452 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
59 ms |
6776 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
1087 ms |
16452 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
1087 ms |
16452 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |