#include "dreaming.h"
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define pii pair<int, int>
#define F first
#define S second
const int N = 100005;
int used[N];
int dis[N];
vector <pii> v[N];
void DFS(int node){
used[node] = 1;
dis[node] = 0;
for(pii i : v[node]){
if(!used[i.F]){
used[i.F] = 1;
DFS(i.F);
dis[node] += i.S + dis[i.F];
}
}
}
int getans(int node, int sum){
used[node] = 0;
int res = sum - dis[node];
for(pii i : v[node]){
if(used[i.F]){
res = max(res, dis[i.F] + i.S);
}
}
for(pii i : v[node]){
if(used[i.F]){
used[i.F] = 0;
res = min(res, getans(i.F, sum));
}
}
return res;
}
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]});
}
for(int i = 0; i < n; i++){
if(!used[i]) {
DFS(i);
}
}
vector<int> results;
for(int i = 0; i < n; i++){
if(used[i] != 0){
int cur = getans(i, dis[i]);
results.pb(cur);
// if(results.size() == 1) return cur;
}
}
sort(results.begin(), results.end());
int sz = results.size();
int 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 |
55 ms |
12284 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 |
55 ms |
12284 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
30 ms |
6464 KB |
Output is correct |
2 |
Correct |
30 ms |
6476 KB |
Output is correct |
3 |
Correct |
23 ms |
6520 KB |
Output is correct |
4 |
Correct |
41 ms |
6476 KB |
Output is correct |
5 |
Correct |
28 ms |
6460 KB |
Output is correct |
6 |
Correct |
26 ms |
6908 KB |
Output is correct |
7 |
Correct |
28 ms |
6608 KB |
Output is correct |
8 |
Correct |
25 ms |
6376 KB |
Output is correct |
9 |
Correct |
28 ms |
6432 KB |
Output is correct |
10 |
Correct |
29 ms |
6640 KB |
Output is correct |
11 |
Correct |
2 ms |
2636 KB |
Output is correct |
12 |
Correct |
6 ms |
4040 KB |
Output is correct |
13 |
Correct |
6 ms |
4068 KB |
Output is correct |
14 |
Correct |
6 ms |
4040 KB |
Output is correct |
15 |
Correct |
6 ms |
4040 KB |
Output is correct |
16 |
Correct |
9 ms |
4084 KB |
Output is correct |
17 |
Correct |
6 ms |
4040 KB |
Output is correct |
18 |
Correct |
6 ms |
4040 KB |
Output is correct |
19 |
Correct |
6 ms |
4056 KB |
Output is correct |
20 |
Correct |
2 ms |
2636 KB |
Output is correct |
21 |
Correct |
2 ms |
2636 KB |
Output is correct |
22 |
Correct |
2 ms |
2636 KB |
Output is correct |
23 |
Correct |
6 ms |
4056 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 |
55 ms |
12284 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |