#include "dreaming.h"
#include <bits/stdc++.h>
using namespace std;
vector <pair <int, int>> ke[100001];
int dp[100001],dp2[100001],ch[100001],mx;
priority_queue <int, vector <int>, greater <int>> q;
void dfs(int u, int p){
ch[u]=1;
for (auto [v,w]:ke[u])
if (v!=p){
dfs(v,u);
dp[u]=max(dp[u],dp[v]+w);
}
}
void dfs2(int u, int p){
ch[u]=0;
int mx=0,idx=-1,mx2=0;
for (auto [v,w]:ke[u]){
if (dp[v]+w>mx){
mx2=mx;
mx=dp[v]+w;
idx=v;
}
else
mx2=max(mx2,dp[v]+w);
}
for (auto [v,w]:ke[u]){
dp2[v]=max(dp2[u],(v==idx?mx:mx2))+w;
dfs2(v,u);
}
}
int travelTime(int N, int M, int L, int A[], int B[], int T[]) {
for (int i=0;i<M;i++)
ke[A[i]].emplace_back(B[i],T[i]);
for (int i=0;i<N;i++)
if (!ch[i])
dfs(i,i);
for (int i=0;i<N;i++){
if (ch[i])
dfs2(i,i);
mx=max(mx,dp[i]);
}
for (int i=0;i<N;i++)
dp[i]=max(dp[i],dp2[i]);
for (int i=0;i<M;i++){
if (dp[A[i]]>dp[B[i]])
ch[A[i]]=1;
else
ch[B[i]]=1;
}
for (int i=0;i<N;i++)
if (!ch[i])
q.push(dp[i]);
while (q.size()>1){
int x=q.top();
q.pop();
int y=q.top();
q.pop();
mx=max(mx,x+y+L);
q.push(min(max(x,y+L),max(x+L,y)));
}
return mx;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
89 ms |
17696 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
4956 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
89 ms |
17696 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
19 ms |
6748 KB |
Output is correct |
2 |
Incorrect |
21 ms |
6764 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
4956 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
89 ms |
17696 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |