# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
26949 |
2017-07-07T11:53:07 Z |
repeating |
Race (IOI11_race) |
C++11 |
|
758 ms |
31436 KB |
#include <bits/stdc++.h>
#include "race.h"
#define F first
#define S second
#define P push
#define pb push_back
#define MEM(dp,i) memset(dp,i,sizeof(dp))
#define W while
#define R return
#define C continue
#define SI size()
#define ll long long
#define ld long double
#define pll pair<ll,ll>
#define pii pair<int,int>
#define SF(x) scanf("%I64d",&x)
#define SF2(x,y) scanf("%I64d%I64d",&x,&y)
#define SF3(x,y,z) scanf("%I64d%I64d%I64d",&x,&y,&z)
#define SF4(x,y,z,o) scanf("%I64d%I64d%I64d%I64d",&x,&y,&z,&o)
#define all(v) v.begin(),v.end()
#define MAX_N 500000
using namespace std;
const long long INF = 1e9+5e8;
const int MX=200009;
int n,k;
int par[MX];
int sub[MX];
int dis[MX];
int ways[MX];
int t[MX*5];
vector<pii> adj[MX];
vector<int> v;
bool blocked[MX];
stack<int> st;
int DFS(int ver){
int ret=1;
v.pb(ver);
for(auto i : adj[ver]){
if(i.F==par[ver]||blocked[i.F])C;
par[i.F]=ver;
ret+=DFS(i.F);
}
sub[ver]=ret;
R ret;
}
int dfs(int ver,ll d,int w,int p){
st.P(ver);
if(d>1000000)R INF;
int ret=INF;
dis[ver]=d;
ways[ver]=w;
if(k>=d){
// cout<<t[k-d]<<endl;
ret=min(ret,t[k-d]+w);
}
for(auto i : adj[ver]){
if(i.F==p||blocked[i.F])C;
ret=min(ret,dfs(i.F,d+i.S,w+1,ver));
}
R ret;
}
int solve(int ver){
int ret=INF;
for(auto i : adj[ver]){
if(blocked[i.F])C;
ret=min(ret,dfs(i.F,i.S,1,ver));
W(!st.empty()){
if(st.top()>=1000000){
st.pop();
C;
}
t[dis[st.top()]]=min(t[dis[st.top()]],ways[st.top()]);
st.pop();
}
}
R ret;
}
int pick(int ver){
int mn=INF,pos=ver;
for(auto i : v){
int mx=v.SI-sub[i];
for(auto j : adj[i]){
if(blocked[j.F]||j.F==par[i])C;
mx=max(mx,sub[j.F]);
}
if(mx<mn){
mn=mx;
pos=i;
}
}
R pos;
}
int creat(int ver){
v.clear();
int ret=INF;
DFS(ver);
int pos=pick(ver);
t[0]=0;
ret=solve(pos);
blocked[pos]=1;
for(auto i : v){
par[i]=-1;
if(0<=dis[i]&&dis[i]<=1000000)
t[dis[i]]=INF;
}
for(auto i : adj[pos]){
if(blocked[i.F])C;
ret=min(ret,creat(i.F));
}
R ret;
}
int best_path(int N, int K, int H[][2], int L[])
{
fill(t,t+1000001,INF);
MEM(par,-1);
n=N,k=K;
for(int i=0;i<n-1;i++){
adj[H[i][0]].pb({H[i][1],L[i]});
adj[H[i][1]].pb({H[i][0],L[i]});
}
int res=creat(0);
if(res==INF)R -1;
else R res;
}
//static int N, K;
//static int H[MAX_N][2];
//static int L[MAX_N];
//static int solution;
//
//inline
//void my_assert(int e) {if (!e) abort();}
//
//void read_input()
//{
// int i;
// my_assert(2==scanf("%d %d",&N,&K));
// for(i=0; i<N-1; i++)
// my_assert(3==scanf("%d %d %d",&H[i][0],&H[i][1],&L[i]));
// my_assert(1==scanf("%d",&solution));
//}
//
//int main()
//{
// int ans;
// read_input();
// ans = best_path(N,K,H,L);
// if(ans==solution)
// printf("Correct.\n");
// else
// printf("Incorrect. Returned %d, Expected %d.\n",ans,solution);
//
// return 0;
//}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
10 ms |
9720 KB |
Output is correct |
2 |
Correct |
10 ms |
9828 KB |
Output is correct |
3 |
Correct |
10 ms |
9828 KB |
Output is correct |
4 |
Correct |
10 ms |
9932 KB |
Output is correct |
5 |
Correct |
9 ms |
9932 KB |
Output is correct |
6 |
Correct |
9 ms |
9968 KB |
Output is correct |
7 |
Correct |
9 ms |
9968 KB |
Output is correct |
8 |
Correct |
9 ms |
9968 KB |
Output is correct |
9 |
Correct |
11 ms |
9968 KB |
Output is correct |
10 |
Correct |
12 ms |
9968 KB |
Output is correct |
11 |
Correct |
9 ms |
9968 KB |
Output is correct |
12 |
Correct |
12 ms |
9968 KB |
Output is correct |
13 |
Correct |
9 ms |
9968 KB |
Output is correct |
14 |
Correct |
10 ms |
9968 KB |
Output is correct |
15 |
Correct |
10 ms |
9968 KB |
Output is correct |
16 |
Correct |
9 ms |
9968 KB |
Output is correct |
17 |
Correct |
9 ms |
9968 KB |
Output is correct |
18 |
Correct |
9 ms |
9968 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
10 ms |
9720 KB |
Output is correct |
2 |
Correct |
10 ms |
9828 KB |
Output is correct |
3 |
Correct |
10 ms |
9828 KB |
Output is correct |
4 |
Correct |
10 ms |
9932 KB |
Output is correct |
5 |
Correct |
9 ms |
9932 KB |
Output is correct |
6 |
Correct |
9 ms |
9968 KB |
Output is correct |
7 |
Correct |
9 ms |
9968 KB |
Output is correct |
8 |
Correct |
9 ms |
9968 KB |
Output is correct |
9 |
Correct |
11 ms |
9968 KB |
Output is correct |
10 |
Correct |
12 ms |
9968 KB |
Output is correct |
11 |
Correct |
9 ms |
9968 KB |
Output is correct |
12 |
Correct |
12 ms |
9968 KB |
Output is correct |
13 |
Correct |
9 ms |
9968 KB |
Output is correct |
14 |
Correct |
10 ms |
9968 KB |
Output is correct |
15 |
Correct |
10 ms |
9968 KB |
Output is correct |
16 |
Correct |
9 ms |
9968 KB |
Output is correct |
17 |
Correct |
9 ms |
9968 KB |
Output is correct |
18 |
Correct |
9 ms |
9968 KB |
Output is correct |
19 |
Correct |
9 ms |
9968 KB |
Output is correct |
20 |
Correct |
10 ms |
9968 KB |
Output is correct |
21 |
Correct |
12 ms |
10064 KB |
Output is correct |
22 |
Correct |
11 ms |
10064 KB |
Output is correct |
23 |
Correct |
11 ms |
10064 KB |
Output is correct |
24 |
Correct |
10 ms |
10064 KB |
Output is correct |
25 |
Correct |
10 ms |
10064 KB |
Output is correct |
26 |
Correct |
11 ms |
10064 KB |
Output is correct |
27 |
Correct |
10 ms |
10064 KB |
Output is correct |
28 |
Correct |
11 ms |
10108 KB |
Output is correct |
29 |
Correct |
11 ms |
10108 KB |
Output is correct |
30 |
Correct |
12 ms |
10108 KB |
Output is correct |
31 |
Correct |
11 ms |
10108 KB |
Output is correct |
32 |
Correct |
13 ms |
10108 KB |
Output is correct |
33 |
Correct |
10 ms |
10108 KB |
Output is correct |
34 |
Correct |
12 ms |
10108 KB |
Output is correct |
35 |
Correct |
10 ms |
10108 KB |
Output is correct |
36 |
Correct |
10 ms |
10228 KB |
Output is correct |
37 |
Correct |
11 ms |
10228 KB |
Output is correct |
38 |
Correct |
12 ms |
10228 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
10 ms |
9720 KB |
Output is correct |
2 |
Correct |
10 ms |
9828 KB |
Output is correct |
3 |
Correct |
10 ms |
9828 KB |
Output is correct |
4 |
Correct |
10 ms |
9932 KB |
Output is correct |
5 |
Correct |
9 ms |
9932 KB |
Output is correct |
6 |
Correct |
9 ms |
9968 KB |
Output is correct |
7 |
Correct |
9 ms |
9968 KB |
Output is correct |
8 |
Correct |
9 ms |
9968 KB |
Output is correct |
9 |
Correct |
11 ms |
9968 KB |
Output is correct |
10 |
Correct |
12 ms |
9968 KB |
Output is correct |
11 |
Correct |
9 ms |
9968 KB |
Output is correct |
12 |
Correct |
12 ms |
9968 KB |
Output is correct |
13 |
Correct |
9 ms |
9968 KB |
Output is correct |
14 |
Correct |
10 ms |
9968 KB |
Output is correct |
15 |
Correct |
10 ms |
9968 KB |
Output is correct |
16 |
Correct |
9 ms |
9968 KB |
Output is correct |
17 |
Correct |
9 ms |
9968 KB |
Output is correct |
18 |
Correct |
9 ms |
9968 KB |
Output is correct |
19 |
Correct |
265 ms |
16648 KB |
Output is correct |
20 |
Correct |
226 ms |
16648 KB |
Output is correct |
21 |
Correct |
231 ms |
16760 KB |
Output is correct |
22 |
Correct |
204 ms |
16760 KB |
Output is correct |
23 |
Correct |
249 ms |
16888 KB |
Output is correct |
24 |
Correct |
161 ms |
16888 KB |
Output is correct |
25 |
Correct |
335 ms |
20232 KB |
Output is correct |
26 |
Correct |
137 ms |
21048 KB |
Output is correct |
27 |
Correct |
341 ms |
23424 KB |
Output is correct |
28 |
Correct |
758 ms |
31436 KB |
Output is correct |
29 |
Correct |
746 ms |
31436 KB |
Output is correct |
30 |
Correct |
264 ms |
31436 KB |
Output is correct |
31 |
Correct |
327 ms |
31436 KB |
Output is correct |
32 |
Correct |
359 ms |
31436 KB |
Output is correct |
33 |
Correct |
584 ms |
31436 KB |
Output is correct |
34 |
Correct |
440 ms |
31436 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
10 ms |
9720 KB |
Output is correct |
2 |
Correct |
10 ms |
9828 KB |
Output is correct |
3 |
Correct |
10 ms |
9828 KB |
Output is correct |
4 |
Correct |
10 ms |
9932 KB |
Output is correct |
5 |
Correct |
9 ms |
9932 KB |
Output is correct |
6 |
Correct |
9 ms |
9968 KB |
Output is correct |
7 |
Correct |
9 ms |
9968 KB |
Output is correct |
8 |
Correct |
9 ms |
9968 KB |
Output is correct |
9 |
Correct |
11 ms |
9968 KB |
Output is correct |
10 |
Correct |
12 ms |
9968 KB |
Output is correct |
11 |
Correct |
9 ms |
9968 KB |
Output is correct |
12 |
Correct |
12 ms |
9968 KB |
Output is correct |
13 |
Correct |
9 ms |
9968 KB |
Output is correct |
14 |
Correct |
10 ms |
9968 KB |
Output is correct |
15 |
Correct |
10 ms |
9968 KB |
Output is correct |
16 |
Correct |
9 ms |
9968 KB |
Output is correct |
17 |
Correct |
9 ms |
9968 KB |
Output is correct |
18 |
Correct |
9 ms |
9968 KB |
Output is correct |
19 |
Correct |
9 ms |
9968 KB |
Output is correct |
20 |
Correct |
10 ms |
9968 KB |
Output is correct |
21 |
Correct |
12 ms |
10064 KB |
Output is correct |
22 |
Correct |
11 ms |
10064 KB |
Output is correct |
23 |
Correct |
11 ms |
10064 KB |
Output is correct |
24 |
Correct |
10 ms |
10064 KB |
Output is correct |
25 |
Correct |
10 ms |
10064 KB |
Output is correct |
26 |
Correct |
11 ms |
10064 KB |
Output is correct |
27 |
Correct |
10 ms |
10064 KB |
Output is correct |
28 |
Correct |
11 ms |
10108 KB |
Output is correct |
29 |
Correct |
11 ms |
10108 KB |
Output is correct |
30 |
Correct |
12 ms |
10108 KB |
Output is correct |
31 |
Correct |
11 ms |
10108 KB |
Output is correct |
32 |
Correct |
13 ms |
10108 KB |
Output is correct |
33 |
Correct |
10 ms |
10108 KB |
Output is correct |
34 |
Correct |
12 ms |
10108 KB |
Output is correct |
35 |
Correct |
10 ms |
10108 KB |
Output is correct |
36 |
Correct |
10 ms |
10228 KB |
Output is correct |
37 |
Correct |
11 ms |
10228 KB |
Output is correct |
38 |
Correct |
12 ms |
10228 KB |
Output is correct |
39 |
Correct |
265 ms |
16648 KB |
Output is correct |
40 |
Correct |
226 ms |
16648 KB |
Output is correct |
41 |
Correct |
231 ms |
16760 KB |
Output is correct |
42 |
Correct |
204 ms |
16760 KB |
Output is correct |
43 |
Correct |
249 ms |
16888 KB |
Output is correct |
44 |
Correct |
161 ms |
16888 KB |
Output is correct |
45 |
Correct |
335 ms |
20232 KB |
Output is correct |
46 |
Correct |
137 ms |
21048 KB |
Output is correct |
47 |
Correct |
341 ms |
23424 KB |
Output is correct |
48 |
Correct |
758 ms |
31436 KB |
Output is correct |
49 |
Correct |
746 ms |
31436 KB |
Output is correct |
50 |
Correct |
264 ms |
31436 KB |
Output is correct |
51 |
Correct |
327 ms |
31436 KB |
Output is correct |
52 |
Correct |
359 ms |
31436 KB |
Output is correct |
53 |
Correct |
584 ms |
31436 KB |
Output is correct |
54 |
Correct |
440 ms |
31436 KB |
Output is correct |
55 |
Correct |
23 ms |
31436 KB |
Output is correct |
56 |
Correct |
20 ms |
31436 KB |
Output is correct |
57 |
Correct |
160 ms |
31436 KB |
Output is correct |
58 |
Correct |
51 ms |
31436 KB |
Output is correct |
59 |
Correct |
127 ms |
31436 KB |
Output is correct |
60 |
Correct |
745 ms |
31436 KB |
Output is correct |
61 |
Correct |
255 ms |
31436 KB |
Output is correct |
62 |
Correct |
269 ms |
31436 KB |
Output is correct |
63 |
Correct |
390 ms |
31436 KB |
Output is correct |
64 |
Correct |
724 ms |
31436 KB |
Output is correct |
65 |
Correct |
377 ms |
31436 KB |
Output is correct |
66 |
Correct |
615 ms |
31436 KB |
Output is correct |
67 |
Correct |
225 ms |
31436 KB |
Output is correct |
68 |
Correct |
406 ms |
31436 KB |
Output is correct |
69 |
Correct |
393 ms |
31436 KB |
Output is correct |
70 |
Correct |
426 ms |
31436 KB |
Output is correct |