#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;
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);
}
}
int mx1 = 0, mx2 = 0;
for(int i = 0; i < n; i++){
if(used[i] != 0){
int cur = getans(i, dis[i]);
if(cur >= mx1) {
mx2 = mx1;
mx1 = cur;
}
else if(cur > mx2) mx2 = cur;
}
}
return mx1 + mx2 + l;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
67 ms |
11960 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
2 ms |
2636 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
67 ms |
11960 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
22 ms |
6088 KB |
Output is correct |
2 |
Incorrect |
30 ms |
6200 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
2 ms |
2636 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
67 ms |
11960 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |