#include "dreaming.h"
#include<bits/stdc++.h>
using namespace std;
vector<vector<pair<int ,int>>> adj;
vector<int> center;
vector<bool> vis;
int mx = 0;
int y = 0;
int z = 0;
void dfs1(int x , int p , int d)
{
vis[x] = 1;
if(mx <= d)
{
mx = d;
y = x;
}
for(auto [u , c] : adj[x])
{
if(u == p)
continue;
dfs1(u , x , d + c);
}
}
vector<pair<int ,int>> par;
void dfs2(int x , int p , int d , int co)
{
par[x] = {p , co};
if(mx <= d)
{
mx = d;
z = x;
}
for(auto [u , c] : adj[x])
{
if(u == p)
continue;
dfs2(u , x , d + c , c);
}
}
int travelTime(int N, int M, int L, int A[], int B[], int T[])
{
adj.assign(N , {});
vis.assign(N , 0);
for(int i = 0 ; i < M; i++)
{
adj[A[i]].push_back({B[i] , T[i]});
adj[B[i]].push_back({A[i] , T[i]});
}
for(int i = 0 ; i < N ; i++)
{
if(!vis[i])
{
y = 0;
mx = 0;
dfs1(i , -1 , 0);
mx = 0;
z = 0;
par.assign(N , {-1 , -1});
dfs2(y , -1 , 0 , 0);
int sm = 0;
int mid = z;
while(par[z].first != -1 && 2 * sm < mx)
{
sm += par[z].second;
mid = par[z].first;
z = par[z].first;
}
center.push_back(mid);
}
}
adj[center[0]].push_back({center[1] ,L});
adj[center[1]].push_back({center[0] , L});
y = mx = 0;
vis.assign(N , 0);
dfs1(0 , -1 , 0);
mx = 0;
z = 0;
dfs2(y , -1 , 0 , 0);
return mx;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
30 ms |
12628 KB |
Output is correct |
2 |
Correct |
32 ms |
12632 KB |
Output is correct |
3 |
Correct |
21 ms |
8532 KB |
Output is correct |
4 |
Correct |
5 ms |
2140 KB |
Output is correct |
5 |
Correct |
4 ms |
1388 KB |
Output is correct |
6 |
Correct |
10 ms |
3164 KB |
Output is correct |
7 |
Correct |
0 ms |
444 KB |
Output is correct |
8 |
Correct |
18 ms |
4876 KB |
Output is correct |
9 |
Correct |
26 ms |
6796 KB |
Output is correct |
10 |
Correct |
1 ms |
348 KB |
Output is correct |
11 |
Correct |
38 ms |
9020 KB |
Output is correct |
12 |
Correct |
40 ms |
10744 KB |
Output is correct |
13 |
Incorrect |
1 ms |
344 KB |
Output isn't correct |
14 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
30 ms |
12628 KB |
Output is correct |
2 |
Correct |
32 ms |
12632 KB |
Output is correct |
3 |
Correct |
21 ms |
8532 KB |
Output is correct |
4 |
Correct |
5 ms |
2140 KB |
Output is correct |
5 |
Correct |
4 ms |
1388 KB |
Output is correct |
6 |
Correct |
10 ms |
3164 KB |
Output is correct |
7 |
Correct |
0 ms |
444 KB |
Output is correct |
8 |
Correct |
18 ms |
4876 KB |
Output is correct |
9 |
Correct |
26 ms |
6796 KB |
Output is correct |
10 |
Correct |
1 ms |
348 KB |
Output is correct |
11 |
Correct |
38 ms |
9020 KB |
Output is correct |
12 |
Correct |
40 ms |
10744 KB |
Output is correct |
13 |
Incorrect |
1 ms |
344 KB |
Output isn't correct |
14 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
1062 ms |
6228 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
30 ms |
12628 KB |
Output is correct |
2 |
Correct |
32 ms |
12632 KB |
Output is correct |
3 |
Correct |
21 ms |
8532 KB |
Output is correct |
4 |
Correct |
5 ms |
2140 KB |
Output is correct |
5 |
Correct |
4 ms |
1388 KB |
Output is correct |
6 |
Correct |
10 ms |
3164 KB |
Output is correct |
7 |
Correct |
0 ms |
444 KB |
Output is correct |
8 |
Correct |
18 ms |
4876 KB |
Output is correct |
9 |
Correct |
26 ms |
6796 KB |
Output is correct |
10 |
Correct |
1 ms |
348 KB |
Output is correct |
11 |
Correct |
38 ms |
9020 KB |
Output is correct |
12 |
Correct |
40 ms |
10744 KB |
Output is correct |
13 |
Incorrect |
1 ms |
344 KB |
Output isn't correct |
14 |
Halted |
0 ms |
0 KB |
- |