#include "dreaming.h"
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define pii pair<int, ll>
#define F first
#define S second
const int N = 100005;
int used[N];
ll dis[N][3];
vector <pii> v[N];
vector <int> vis;
void DFS(int node, int r){
used[node] = 1;
vis.pb(node);
for(pii i : v[node]){
if(!used[i.F]){
used[i.F] = 1;
dis[i.F][r] = dis[node][r] + i.S;
DFS(i.F, r);
}
}
}
int travelTime(int n, int m, int l, int a[], int b[], int t[]) {
if(n == 1) return 0;
for(int i = 0; i < m; i++){
v[a[i]].pb({b[i], t[i]});
v[b[i]].pb({a[i], t[i]});
}
vector<ll> results;
for(int i = 0; i < n; i++){
if(!used[i]) {
ll mx = 0, dd = i;
dis[dd][0] = 0;
DFS(dd, 0);
for(int j : vis){
used[j] = 0;
if(dis[j][0] >= mx) {
mx = dis[j][0];
dd = j;
}
dis[j][0] = 0;
}
vis.clear();
dis[dd][0] = 0;
DFS(dd, 0);
mx = 0;
for(int j : vis){
used[j] = 0;
if(dis[j][0] >= mx) {
mx = dis[j][0];
dd = j;
}
}
vis.clear();
dis[dd][1] = 0;
DFS(dd, 1);
ll res = mx;
for(int j : vis){
res = min(res, max(dis[j][0], dis[j][1]));
}
vis.clear();
results.pb(res);
}
}
sort(results.begin(), results.end());
int sz = results.size();
ll ans = results[sz - 1];
if(sz >= 2) ans += results[sz - 2] + l;
if(sz >= 3) ans = max(ans, results[sz - 2] + results[sz - 3] + l + l);
return ans;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
78 ms |
17880 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
3 ms |
2636 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
78 ms |
17880 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
34 ms |
8600 KB |
Output is correct |
2 |
Correct |
41 ms |
8644 KB |
Output is correct |
3 |
Correct |
34 ms |
8556 KB |
Output is correct |
4 |
Correct |
34 ms |
8500 KB |
Output is correct |
5 |
Correct |
45 ms |
8580 KB |
Output is correct |
6 |
Correct |
39 ms |
9412 KB |
Output is correct |
7 |
Correct |
43 ms |
8796 KB |
Output is correct |
8 |
Correct |
53 ms |
8396 KB |
Output is correct |
9 |
Correct |
31 ms |
8420 KB |
Output is correct |
10 |
Correct |
46 ms |
8712 KB |
Output is correct |
11 |
Correct |
3 ms |
2636 KB |
Output is correct |
12 |
Correct |
13 ms |
6296 KB |
Output is correct |
13 |
Correct |
12 ms |
6340 KB |
Output is correct |
14 |
Correct |
13 ms |
6208 KB |
Output is correct |
15 |
Correct |
12 ms |
6300 KB |
Output is correct |
16 |
Correct |
14 ms |
6224 KB |
Output is correct |
17 |
Correct |
12 ms |
6240 KB |
Output is correct |
18 |
Correct |
11 ms |
6376 KB |
Output is correct |
19 |
Correct |
10 ms |
6208 KB |
Output is correct |
20 |
Correct |
3 ms |
2636 KB |
Output is correct |
21 |
Correct |
3 ms |
2636 KB |
Output is correct |
22 |
Correct |
4 ms |
2692 KB |
Output is correct |
23 |
Correct |
10 ms |
6264 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
3 ms |
2636 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
78 ms |
17880 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |