# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
945466 |
2024-03-13T21:06:24 Z |
4QT0R |
Dreaming (IOI13_dreaming) |
C++17 |
|
32 ms |
16856 KB |
#include <bits/stdc++.h>
#include "dreaming.h"
using namespace std;
vector<pair<int,int>> graph[100003];
int odl[100003];
int comp[100003];
vector<int> diameter[100003];
int len[100003];
int iter=0,mx_odl,mx_ver,ans=-1;
void dfs(int v, int p){
comp[v]=iter;
if (odl[v]>mx_odl){
mx_odl=odl[v];
mx_ver=v;
}
for (auto u : graph[v]){
if (u.first==p)continue;
odl[u.first]=odl[v]+u.second;
dfs(u.first,v);
}
}
void farthest(int v){
mx_odl=mx_ver=-1;
odl[v]=0;
dfs(v,-1);
}
bool build_diameter(int v, int p, int fin){
diameter[iter].push_back(v);
if (v==fin)return true;
for (auto u : graph[v]){
if (u.first==p)continue;
if (build_diameter(u.first,v,fin))return true;
}
diameter[iter].pop_back();
return false;
}
int find_diameter(int v){
iter++;
farthest(v);
int st=mx_ver;
farthest(st);
int nd=mx_ver;
len[iter]=mx_odl;
ans=max(ans,len[iter]);
build_diameter(st,-1,nd);
int mn=1e9+1,wyn=0;
for (int i = 0; i<(int)diameter[iter].size(); i++){
if (abs(mx_odl-2*odl[diameter[iter][i]])<mn){
mn=abs(mx_odl-2*odl[diameter[iter][i]]);
wyn=odl[diameter[iter][i]];
}
}
return max(wyn,mx_odl-wyn);
}
int travelTime(int n, int m, int L, int A[], int B[], int T[]){
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]});
}
int maxy[3]={-1,-1,-1};
int val;
for (int i = 0; i<n; i++){
if (!comp[i]){
val=find_diameter(i);
if (val>maxy[0]){
maxy[2]=maxy[1];
maxy[1]=maxy[0];
maxy[0]=val;
}
else if (val>maxy[1]){
maxy[2]=maxy[1];
maxy[1]=val;
}
else if (val>maxy[2]){
maxy[2]=val;
}
}
}
if (m==n-1)ans=max(ans,maxy[0]+maxy[1]+L);
else if (m<n-1)ans=max({ans,maxy[0]+maxy[1]+L,maxy[1]+maxy[2]+2*L});
return ans;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
31 ms |
16676 KB |
Output is correct |
2 |
Correct |
32 ms |
16856 KB |
Output is correct |
3 |
Correct |
23 ms |
13396 KB |
Output is correct |
4 |
Correct |
6 ms |
8540 KB |
Output is correct |
5 |
Correct |
5 ms |
8028 KB |
Output is correct |
6 |
Correct |
9 ms |
9308 KB |
Output is correct |
7 |
Incorrect |
1 ms |
7260 KB |
Output isn't correct |
8 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
7260 KB |
Output is correct |
2 |
Correct |
2 ms |
7260 KB |
Output is correct |
3 |
Incorrect |
2 ms |
7256 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
31 ms |
16676 KB |
Output is correct |
2 |
Correct |
32 ms |
16856 KB |
Output is correct |
3 |
Correct |
23 ms |
13396 KB |
Output is correct |
4 |
Correct |
6 ms |
8540 KB |
Output is correct |
5 |
Correct |
5 ms |
8028 KB |
Output is correct |
6 |
Correct |
9 ms |
9308 KB |
Output is correct |
7 |
Incorrect |
1 ms |
7260 KB |
Output isn't correct |
8 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
15 ms |
11180 KB |
Output is correct |
2 |
Correct |
17 ms |
11168 KB |
Output is correct |
3 |
Correct |
15 ms |
11096 KB |
Output is correct |
4 |
Correct |
16 ms |
11096 KB |
Output is correct |
5 |
Correct |
17 ms |
11100 KB |
Output is correct |
6 |
Correct |
16 ms |
11356 KB |
Output is correct |
7 |
Correct |
17 ms |
11352 KB |
Output is correct |
8 |
Correct |
15 ms |
11100 KB |
Output is correct |
9 |
Correct |
15 ms |
11100 KB |
Output is correct |
10 |
Correct |
17 ms |
11288 KB |
Output is correct |
11 |
Correct |
1 ms |
7256 KB |
Output is correct |
12 |
Correct |
7 ms |
10332 KB |
Output is correct |
13 |
Correct |
7 ms |
10332 KB |
Output is correct |
14 |
Correct |
8 ms |
10584 KB |
Output is correct |
15 |
Correct |
7 ms |
10228 KB |
Output is correct |
16 |
Correct |
6 ms |
10332 KB |
Output is correct |
17 |
Correct |
7 ms |
10332 KB |
Output is correct |
18 |
Correct |
7 ms |
10332 KB |
Output is correct |
19 |
Correct |
7 ms |
10448 KB |
Output is correct |
20 |
Incorrect |
1 ms |
7260 KB |
Output isn't correct |
21 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
7260 KB |
Output is correct |
2 |
Correct |
2 ms |
7260 KB |
Output is correct |
3 |
Incorrect |
2 ms |
7256 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
31 ms |
16676 KB |
Output is correct |
2 |
Correct |
32 ms |
16856 KB |
Output is correct |
3 |
Correct |
23 ms |
13396 KB |
Output is correct |
4 |
Correct |
6 ms |
8540 KB |
Output is correct |
5 |
Correct |
5 ms |
8028 KB |
Output is correct |
6 |
Correct |
9 ms |
9308 KB |
Output is correct |
7 |
Incorrect |
1 ms |
7260 KB |
Output isn't correct |
8 |
Halted |
0 ms |
0 KB |
- |