# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
920440 |
2024-02-02T14:41:43 Z |
Arp |
Dreaming (IOI13_dreaming) |
C++17 |
|
45 ms |
13120 KB |
#include<bits/stdc++.h>
#include "dreaming.h"
using namespace std;
const int N = 1e5;
const int inf = 2e9;
vector<pair<int,int>> adj[N];
int down[N],up[N];
bool vis[N];
void dfs(int u){
vis[u] = true;
vector<pair<int,int>> all;
for(auto [v,w] : adj[u]){
if(vis[v]) continue;
dfs(v);
all.emplace_back(v,w);
}
int maxi = -inf;
for(auto [v,w] : all){
up[v] = max(up[v],maxi + w);
maxi = max(maxi,down[v] + w);
}
reverse(all.begin(),all.end());
maxi = -inf;
for(auto [v,w] : all){
up[v] = max(up[v],maxi + w);
maxi = max(maxi,down[v] + w);
down[u] = maxi;
}
}
int mini = inf;
void dfs2(int u,int p){
for(auto[v,w] : adj[u]){
if(v == p) continue;
up[v] = max(up[v],up[u] + w);
dfs2(v,u);
}
mini = min(mini,max(down[u],up[u]));
}
int travelTime(int N,int M,int L,int A[],int B[],int T[]){
for(int i = 0;i<N;i++){
up[i] = down[i] = 0;
vis[i] = false;
}
for(int i = 0;i<M;i++){
adj[A[i]].emplace_back(B[i],T[i]);
adj[B[i]].emplace_back(A[i],T[i]);
}
vector<int> arr;
int ans = 0;
int cc = 0;
for(int i = 0;i<N;i++){
if(!vis[i]){
mini = inf;
// cout << i << " Doing\n";
dfs(i);
dfs2(i,-1);
arr.push_back(mini);
cc ++;
}
ans = max(ans,up[i]);
}
assert(cc - 1 == N - M - 1);
sort(arr.begin(),arr.end());
int tot = inf;
if(arr.size() == 2){
ans = max(ans,arr[0] + arr[1] + L);
}else if(arr.size() > 2){
int a = arr[arr.size() - 3];
int b = arr[arr.size() - 2];
int c = arr[arr.size() - 1];
// cout << a << " " << b << " " << c << '\n';
tot = min(tot,max(b + c + L,a + c + 2 * L));
tot = min(tot,max(b + c + L,a + b + 2 * L));
}
for(int i = 0;i<N;i++){
// cout << up[i] << " " << down[i] << '\n';
}
return max(tot,ans);
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
45 ms |
13120 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
4440 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
45 ms |
13120 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
19 ms |
7512 KB |
Output is correct |
2 |
Correct |
21 ms |
7512 KB |
Output is correct |
3 |
Correct |
15 ms |
7512 KB |
Output is correct |
4 |
Correct |
15 ms |
7512 KB |
Output is correct |
5 |
Correct |
22 ms |
7512 KB |
Output is correct |
6 |
Correct |
16 ms |
7900 KB |
Output is correct |
7 |
Correct |
15 ms |
7644 KB |
Output is correct |
8 |
Correct |
14 ms |
7504 KB |
Output is correct |
9 |
Correct |
13 ms |
7380 KB |
Output is correct |
10 |
Correct |
17 ms |
7628 KB |
Output is correct |
11 |
Correct |
2 ms |
4444 KB |
Output is correct |
12 |
Correct |
4 ms |
5336 KB |
Output is correct |
13 |
Correct |
4 ms |
5332 KB |
Output is correct |
14 |
Correct |
4 ms |
5336 KB |
Output is correct |
15 |
Correct |
5 ms |
5336 KB |
Output is correct |
16 |
Correct |
4 ms |
5332 KB |
Output is correct |
17 |
Correct |
3 ms |
5080 KB |
Output is correct |
18 |
Correct |
4 ms |
5332 KB |
Output is correct |
19 |
Correct |
4 ms |
5332 KB |
Output is correct |
20 |
Incorrect |
1 ms |
4440 KB |
Output isn't correct |
21 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
4440 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
45 ms |
13120 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |