# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
200033 |
2020-02-05T03:20:15 Z |
AQT |
Dreaming (IOI13_dreaming) |
C++14 |
|
136 ms |
16632 KB |
#include "dreaming.h"
#include <bits/stdc++.h>
using namespace std;
int N, M, L;
vector<pair<int, int>> graph[100005];
long long dist[2][100005];
bool vis[100005];
long long dfs(int n, int t, int p){
int ret = n;
vis[n] = 1;
for(auto e : graph[n]){
if(e.first != p){
dist[t][e.first] = dist[t][n] + e.second;
int k = dfs(e.first, t, n);
if(dist[t][k] > dist[t][ret]){
ret = k;
}
}
}
return ret;
}
long long solve(int n, int p){
long long ret = max(dist[0][n], dist[1][n]);
for(auto e : graph[n]){
if(e.first != p){
long long k = solve(e.first, n);
ret = min(k, ret);
}
}
return ret;
}
int travelTime(int n, int m, int l, int A[], int B[], int T[]){
N = n, M = m, l = L;
for(int i = 0; i<M;i ++){
graph[A[i]].push_back({B[i], T[i]});
graph[B[i]].push_back({A[i], T[i]});
}
vector<long long> v;
long long ans = 0;
for(int i = 1; i<=N; i++){
if(!vis[i]){
int n = dfs(1, 0, 0);
dist[0][n] = 0;
n = dfs(n, 0, 0);
ans = max(ans, dist[0][n] + dist[1][n]);
dfs(n, 1, 0);
long long r = solve(n, 0);
v.push_back(r);
}
}
sort(v.begin(), v.end(), greater<long long> ());
if(v.size() >= 2){
ans = max(ans, v[0] + v[1] + l);
}
if(v.size() >= 3){
ans = max(ans, v[1] + v[2] + 2*l);
}
return ans;
}
/*
int main(){
}
*/
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
136 ms |
16632 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
136 ms |
16632 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
136 ms |
16632 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
30 ms |
6644 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
136 ms |
16632 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
136 ms |
16632 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |