#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?mx2:mx))+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;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
76 ms |
16300 KB |
Output is correct |
2 |
Correct |
90 ms |
17640 KB |
Output is correct |
3 |
Correct |
59 ms |
13400 KB |
Output is correct |
4 |
Correct |
8 ms |
6748 KB |
Output is correct |
5 |
Correct |
7 ms |
5724 KB |
Output is correct |
6 |
Correct |
19 ms |
7608 KB |
Output is correct |
7 |
Correct |
2 ms |
4960 KB |
Output is correct |
8 |
Correct |
34 ms |
9160 KB |
Output is correct |
9 |
Correct |
48 ms |
11116 KB |
Output is correct |
10 |
Correct |
2 ms |
4956 KB |
Output is correct |
11 |
Correct |
69 ms |
12844 KB |
Output is correct |
12 |
Correct |
111 ms |
15132 KB |
Output is correct |
13 |
Correct |
2 ms |
4952 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
2 ms |
4956 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
76 ms |
16300 KB |
Output is correct |
2 |
Correct |
90 ms |
17640 KB |
Output is correct |
3 |
Correct |
59 ms |
13400 KB |
Output is correct |
4 |
Correct |
8 ms |
6748 KB |
Output is correct |
5 |
Correct |
7 ms |
5724 KB |
Output is correct |
6 |
Correct |
19 ms |
7608 KB |
Output is correct |
7 |
Correct |
2 ms |
4960 KB |
Output is correct |
8 |
Correct |
34 ms |
9160 KB |
Output is correct |
9 |
Correct |
48 ms |
11116 KB |
Output is correct |
10 |
Correct |
2 ms |
4956 KB |
Output is correct |
11 |
Correct |
69 ms |
12844 KB |
Output is correct |
12 |
Correct |
111 ms |
15132 KB |
Output is correct |
13 |
Correct |
2 ms |
4952 KB |
Output is correct |
14 |
Incorrect |
2 ms |
4956 KB |
Output isn't correct |
15 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
19 ms |
6356 KB |
Output is correct |
2 |
Incorrect |
20 ms |
6556 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
2 ms |
4956 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
76 ms |
16300 KB |
Output is correct |
2 |
Correct |
90 ms |
17640 KB |
Output is correct |
3 |
Correct |
59 ms |
13400 KB |
Output is correct |
4 |
Correct |
8 ms |
6748 KB |
Output is correct |
5 |
Correct |
7 ms |
5724 KB |
Output is correct |
6 |
Correct |
19 ms |
7608 KB |
Output is correct |
7 |
Correct |
2 ms |
4960 KB |
Output is correct |
8 |
Correct |
34 ms |
9160 KB |
Output is correct |
9 |
Correct |
48 ms |
11116 KB |
Output is correct |
10 |
Correct |
2 ms |
4956 KB |
Output is correct |
11 |
Correct |
69 ms |
12844 KB |
Output is correct |
12 |
Correct |
111 ms |
15132 KB |
Output is correct |
13 |
Correct |
2 ms |
4952 KB |
Output is correct |
14 |
Incorrect |
2 ms |
4956 KB |
Output isn't correct |
15 |
Halted |
0 ms |
0 KB |
- |