#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][2];
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[]) {
// return n;
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);
for(int j : vis){
mx = min(mx, max(dis[j][0], dis[j][1]));
}
vis.clear();
results.pb(mx);
}
}
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;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
86 ms |
17108 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
3 ms |
2636 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
86 ms |
17108 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
31 ms |
7840 KB |
Output is correct |
2 |
Correct |
44 ms |
7824 KB |
Output is correct |
3 |
Correct |
43 ms |
7812 KB |
Output is correct |
4 |
Correct |
38 ms |
7784 KB |
Output is correct |
5 |
Correct |
41 ms |
7808 KB |
Output is correct |
6 |
Correct |
46 ms |
8596 KB |
Output is correct |
7 |
Correct |
44 ms |
8024 KB |
Output is correct |
8 |
Correct |
33 ms |
7692 KB |
Output is correct |
9 |
Correct |
45 ms |
7772 KB |
Output is correct |
10 |
Correct |
46 ms |
8016 KB |
Output is correct |
11 |
Correct |
3 ms |
2636 KB |
Output is correct |
12 |
Correct |
12 ms |
5604 KB |
Output is correct |
13 |
Correct |
12 ms |
5728 KB |
Output is correct |
14 |
Correct |
10 ms |
5444 KB |
Output is correct |
15 |
Correct |
10 ms |
5572 KB |
Output is correct |
16 |
Correct |
10 ms |
5444 KB |
Output is correct |
17 |
Correct |
9 ms |
5440 KB |
Output is correct |
18 |
Correct |
17 ms |
5728 KB |
Output is correct |
19 |
Correct |
15 ms |
5444 KB |
Output is correct |
20 |
Correct |
3 ms |
2688 KB |
Output is correct |
21 |
Correct |
4 ms |
2636 KB |
Output is correct |
22 |
Correct |
3 ms |
2764 KB |
Output is correct |
23 |
Correct |
16 ms |
5572 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
3 ms |
2636 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
86 ms |
17108 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |