#include "dreaming.h"
#include <bits/stdc++.h>
using namespace std;
bool viz[100005];
vector<pair<int,int>> g[100005];
int t[100005];
int dist[100005];
vector<int> cc;
void dfs(int nod)
{
cc.push_back(nod);
viz[nod] = true;
for (auto vecin : g[nod])
{
if (!viz[vecin.first])
{
t[vecin.first] = nod;
dist[vecin.first] = dist[nod] + vecin.second;
dfs(vecin.first);
}
}
}
int travelTime(int N, int M, int L, int A[], int B[], int T[])
{
for (int i = 0; i < M; i++)
{
g[A[i]].push_back({B[i],T[i]});
g[B[i]].push_back({A[i],T[i]});
}
vector<int> w;
for (int i = 0; i < N; i++)
{
if (!viz[i])
{
cc.clear();
dfs(i);
int mx = 0,cn = i;
for (auto it : cc)
{
if (dist[it] > mx)
mx = dist[it],cn = it;
}
for (auto it : cc)
dist[it] = 0,viz[it] = false,t[it] = 0;
cc.clear();
dfs(cn);
int rt = cn;
mx = 0,cn = rt;
for (auto it : cc)
{
if (dist[it] > mx)
mx = dist[it],cn = it;
}
vector<int> diam;
while (cn != rt)
diam.push_back(cn),cn = t[cn];
diam.push_back(cn);
int ans = 1e9;
for (auto it : diam)
ans = min(ans,max(dist[it],mx - dist[it]));
w.push_back(ans);
}
}
if (w.size() == 1)
return w[0];
else
{
sort(w.begin(),w.end());
int ans = w[w.size() - 1] + w[w.size() - 2] + L;
if (w.size() >= 3)
ans = max(ans,w[w.size() - 2] + w[w.size() - 3] + L + L);
return ans;
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
44 ms |
15460 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
2652 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
44 ms |
15460 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
16 ms |
6748 KB |
Output is correct |
2 |
Correct |
16 ms |
6744 KB |
Output is correct |
3 |
Correct |
15 ms |
7000 KB |
Output is correct |
4 |
Correct |
17 ms |
6748 KB |
Output is correct |
5 |
Correct |
15 ms |
6748 KB |
Output is correct |
6 |
Correct |
20 ms |
7088 KB |
Output is correct |
7 |
Correct |
15 ms |
6880 KB |
Output is correct |
8 |
Correct |
15 ms |
6624 KB |
Output is correct |
9 |
Correct |
18 ms |
6664 KB |
Output is correct |
10 |
Correct |
15 ms |
6872 KB |
Output is correct |
11 |
Correct |
1 ms |
2804 KB |
Output is correct |
12 |
Correct |
5 ms |
4208 KB |
Output is correct |
13 |
Correct |
6 ms |
4308 KB |
Output is correct |
14 |
Correct |
5 ms |
4312 KB |
Output is correct |
15 |
Correct |
6 ms |
4312 KB |
Output is correct |
16 |
Correct |
5 ms |
4312 KB |
Output is correct |
17 |
Correct |
6 ms |
4128 KB |
Output is correct |
18 |
Correct |
7 ms |
4400 KB |
Output is correct |
19 |
Correct |
5 ms |
4312 KB |
Output is correct |
20 |
Correct |
1 ms |
2804 KB |
Output is correct |
21 |
Correct |
1 ms |
2728 KB |
Output is correct |
22 |
Correct |
1 ms |
2652 KB |
Output is correct |
23 |
Correct |
5 ms |
4312 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
2652 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
44 ms |
15460 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |