# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
316736 |
2020-10-27T17:04:58 Z |
neki |
Dreaming (IOI13_dreaming) |
C++14 |
|
99 ms |
21624 KB |
#include <bits/stdc++.h>
#include"dreaming.h"
#define loop(i, a, b) for(long long i=a;i<b;i++)
#define pool(i, a, b) for(long long i=a-1;i>=b;i--)
#define fore(i, a) for(auto&& i:a)
#define fi first
#define se second
#define ps(a) push_back(a)
#define pb(a) pop_back(a)
#define sc scanf
#define vc vector
#define pa pair<ll, ll>
#define ll long long
#define lb lower_bound
#define ub upper_bound
#define all(a) a.begin(), a.end()
#define llmax LLONG_MAX/2
#define llmin -LLONG_MAX/2
using namespace std;
#define mn 200100
#define pa pair<ll, ll>
#define ld long double
#define k 450
vc<pa> edg[mn];
vc<ll> ne;
ll v1[mn], v2[mn], dp[mn], ans=0;
void dfs1(ll u){
v1[u]=1;
fore(v, edg[u]) if(!v1[v.fi])dfs1(v.fi), dp[u]=max(dp[u], dp[v.fi]+v.se);
}
ll dfs2(ll u, ll cur){
v2[u]=1;
ans=max(ans, dp[u]);
if(cur==-1){
if(edg[u].size()==0) return 0;
if(edg[u].size()==1) return min(dp[u], dfs2(edg[u][0].fi, edg[u][0].se));
}
ll ret=max(cur, dp[u]);
vc<ll> srt;if(cur!=-1) srt.ps(cur);
fore(v, edg[u]) if(!v2[v.fi]) srt.ps(dp[v.fi]+v.se);
sort(all(srt));ll siz=srt.size(); if(siz>1) ans=max(ans, srt[siz-2]+srt[siz-1]);
fore(v, edg[u]) if(!v2[v.fi]){
if(dp[v.fi]+v.se==srt[siz-1]) ret=min(ret, dfs2(v.fi, srt[siz-2]+v.se));
else ret=min(ret, dfs2(v.fi, srt[siz-1]+v.se));
}
return ret;
}
int travelTime(int n,int m,int L, int a[],int b[],int t[]){
loop(i, 0, m) edg[a[i]].ps(make_pair(b[i], t[i]));
loop(i, 0, m) edg[b[i]].ps(make_pair(a[i], t[i]));
loop(i, 0, n){
if(!v1[i])dfs1(i);
if(!v2[i]) ne.ps((dfs2(i, -1)));
}
sort(all(ne));ll siz=ne.size();
if(ne.size()==1) return max(ne[0], ans);
if(ne.size()==2) return max(ne[1]+ne[2]+L, ans);
return max(ans, max(ne[siz-1]+ne[siz-2]+L, ne[siz-3]+ne[siz-2]+2 * L));
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
99 ms |
21624 KB |
Output is correct |
2 |
Correct |
83 ms |
21112 KB |
Output is correct |
3 |
Correct |
55 ms |
18936 KB |
Output is correct |
4 |
Correct |
13 ms |
7408 KB |
Output is correct |
5 |
Correct |
11 ms |
6400 KB |
Output is correct |
6 |
Correct |
20 ms |
8832 KB |
Output is correct |
7 |
Incorrect |
5 ms |
5248 KB |
Output isn't correct |
8 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
99 ms |
21624 KB |
Output is correct |
2 |
Correct |
83 ms |
21112 KB |
Output is correct |
3 |
Correct |
55 ms |
18936 KB |
Output is correct |
4 |
Correct |
13 ms |
7408 KB |
Output is correct |
5 |
Correct |
11 ms |
6400 KB |
Output is correct |
6 |
Correct |
20 ms |
8832 KB |
Output is correct |
7 |
Incorrect |
5 ms |
5248 KB |
Output isn't correct |
8 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
99 ms |
21624 KB |
Output is correct |
2 |
Correct |
83 ms |
21112 KB |
Output is correct |
3 |
Correct |
55 ms |
18936 KB |
Output is correct |
4 |
Correct |
13 ms |
7408 KB |
Output is correct |
5 |
Correct |
11 ms |
6400 KB |
Output is correct |
6 |
Correct |
20 ms |
8832 KB |
Output is correct |
7 |
Incorrect |
5 ms |
5248 KB |
Output isn't correct |
8 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
34 ms |
10612 KB |
Output is correct |
2 |
Correct |
32 ms |
10656 KB |
Output is correct |
3 |
Correct |
34 ms |
10612 KB |
Output is correct |
4 |
Correct |
44 ms |
10612 KB |
Output is correct |
5 |
Correct |
32 ms |
10612 KB |
Output is correct |
6 |
Correct |
35 ms |
11516 KB |
Output is correct |
7 |
Correct |
33 ms |
10868 KB |
Output is correct |
8 |
Correct |
32 ms |
10492 KB |
Output is correct |
9 |
Correct |
31 ms |
10488 KB |
Output is correct |
10 |
Correct |
33 ms |
10736 KB |
Output is correct |
11 |
Correct |
4 ms |
4992 KB |
Output is correct |
12 |
Correct |
8 ms |
8184 KB |
Output is correct |
13 |
Correct |
9 ms |
8312 KB |
Output is correct |
14 |
Correct |
9 ms |
8056 KB |
Output is correct |
15 |
Correct |
9 ms |
8184 KB |
Output is correct |
16 |
Correct |
8 ms |
8056 KB |
Output is correct |
17 |
Correct |
8 ms |
7668 KB |
Output is correct |
18 |
Correct |
9 ms |
8312 KB |
Output is correct |
19 |
Correct |
8 ms |
8056 KB |
Output is correct |
20 |
Correct |
3 ms |
4992 KB |
Output is correct |
21 |
Correct |
3 ms |
4992 KB |
Output is correct |
22 |
Correct |
4 ms |
5120 KB |
Output is correct |
23 |
Correct |
9 ms |
8056 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
99 ms |
21624 KB |
Output is correct |
2 |
Correct |
83 ms |
21112 KB |
Output is correct |
3 |
Correct |
55 ms |
18936 KB |
Output is correct |
4 |
Correct |
13 ms |
7408 KB |
Output is correct |
5 |
Correct |
11 ms |
6400 KB |
Output is correct |
6 |
Correct |
20 ms |
8832 KB |
Output is correct |
7 |
Incorrect |
5 ms |
5248 KB |
Output isn't correct |
8 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
99 ms |
21624 KB |
Output is correct |
2 |
Correct |
83 ms |
21112 KB |
Output is correct |
3 |
Correct |
55 ms |
18936 KB |
Output is correct |
4 |
Correct |
13 ms |
7408 KB |
Output is correct |
5 |
Correct |
11 ms |
6400 KB |
Output is correct |
6 |
Correct |
20 ms |
8832 KB |
Output is correct |
7 |
Incorrect |
5 ms |
5248 KB |
Output isn't correct |
8 |
Halted |
0 ms |
0 KB |
- |