# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
14670 |
2015-06-01T14:58:57 Z |
minsu |
Race (IOI11_race) |
C++14 |
|
829 ms |
26512 KB |
#include <bits/stdc++.h>
#define SZ(X) ((int)(X).size())
#define ALL(X) (X).begin(), (X).end()
#define REP(I, N) for (int I = 0; I < (N); ++I)
#define REPP(I, A, B) for (int I = (A); I < (B); ++I)
#define RREP(I, N) for (int I= (N)-1; I>=0; --I)
#define RREPP(I, A, B) for(int I = (B)-1; I>=A; --I)
#define CASET int ___T, case_n = 1; scanf("%d ", &___T); while (___T-- > 0)
#define MP make_pair
#define PB push_back
#define MS0(X) memset((X), 0, sizeof((X)))
#define MS1(X) memset((X), -1, sizeof((X)))
#define LEN(X) strlen(X)
#define F first
#define S second
#define debug(A) REP(i, A.size()) cerr << A[i] << ' '; cerr << '\n'
using namespace std;
typedef pair<int, int> ii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ii> vii;
typedef long long lld;
typedef unsigned long long ulld;
typedef pair<lld, lld> plld;
typedef vector<lld> vlld;
typedef vector<vlld> vvlld;
typedef long double ld;
typedef vector<ld> vld;
typedef vector<vld> vvld;
const int MAXN=5e5+10;
const int MAXK=1e6+10;
const int INF=987654321;
struct Edge{ int to, co; };
typedef vector< vector<Edge> > vve;
vve linked; vi deleted;
int n, k, size[MAXN], par[MAXN], A[MAXK], AR[MAXK];
int solve(int root){
struct Sres{ int now, nowk, len, iter, par; };
int ret=INF;
for(auto it : linked[root]){
if( deleted[it.to] ) continue;
vii paths; stack<Sres> st; st.push({it.to, it.co, 1, 0, root});
while(!st.empty()){
Sres& here=st.top();
if(SZ(linked[here.now]) == here.iter) {
paths.PB( {here.nowk, here.len} );
st.pop(); continue;
}
Edge there=linked[here.now][here.iter]; here.iter++;
if( there.to==here.par || deleted[there.to] ) { continue; }
if( here.nowk + there.co <= k )
st.push({there.to, here.nowk + there.co, here.len+1, 0, here.now});
}
for(auto it : paths)
if(AR[k-it.F]==root && A[k-it.F]) ret=min(ret, A[k-it.F] + it.S);
for(auto it : paths){
A[it.F]=min( ( AR[it.F] != root ? INF : A[it.F] ), it.S);
AR[it.F]=root;
}
} if(AR[k]==root && A[k]) ret=min(ret, A[k]);
return ret;
}
int dnc(int root){
struct Sres{ int now, iter; };
vi vs; stack<Sres> st; st.push({root, 0}); par[root]=-1; size[root]=1;
while(!st.empty()){
Sres& here=st.top();
if(SZ(linked[here.now])==here.iter){
vs.PB(here.now);
if(par[here.now]!=-1) size[par[here.now]]+=size[here.now];
st.pop(); continue;
}
Edge there=linked[here.now][here.iter]; here.iter++;
if(deleted[there.to] || there.to==par[here.now]) { continue; }
par[there.to]=here.now; st.push({there.to, 0}); size[there.to]=1;
}
int sn=SZ(vs), nroot=-1;
if(sn==1) return INF;
for(auto it : vs){
int maxi=0;
for(auto there : linked[it]){
if(deleted[there.to]) continue;
if(par[it] == there.to) maxi=max(maxi, sn-size[it]);
else maxi=max(maxi, size[there.to]);
}
if(maxi<=sn/2) { nroot=it; break; }
} assert(nroot!=-1);
int ret=solve(nroot); deleted[nroot]=1;
for(auto it : linked[nroot]){
if(deleted[it.to]) continue;
ret=min(ret, dnc(it.to));
}
return ret;
}
int best_path(int N, int K, int H[][2], int L[]){
vve(N).swap(linked); vi(N, 0).swap(deleted); MS0(A); MS0(AR);
for(int i=0;i<N-1;i++){
linked[H[i][0]].PB({H[i][1], L[i]});
linked[H[i][1]].PB({H[i][0], L[i]});
} n=N, k=K;
int ret=dnc(0);
return ( ret==INF )? -1 : ret;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
9 ms |
8144 KB |
Output is correct |
2 |
Correct |
9 ms |
8356 KB |
Output is correct |
3 |
Correct |
8 ms |
8356 KB |
Output is correct |
4 |
Correct |
7 ms |
8356 KB |
Output is correct |
5 |
Correct |
7 ms |
8356 KB |
Output is correct |
6 |
Correct |
8 ms |
8356 KB |
Output is correct |
7 |
Correct |
7 ms |
8356 KB |
Output is correct |
8 |
Correct |
7 ms |
8392 KB |
Output is correct |
9 |
Correct |
8 ms |
8392 KB |
Output is correct |
10 |
Correct |
8 ms |
8392 KB |
Output is correct |
11 |
Correct |
7 ms |
8392 KB |
Output is correct |
12 |
Correct |
9 ms |
8392 KB |
Output is correct |
13 |
Correct |
9 ms |
8400 KB |
Output is correct |
14 |
Correct |
9 ms |
8480 KB |
Output is correct |
15 |
Correct |
8 ms |
8480 KB |
Output is correct |
16 |
Correct |
9 ms |
8480 KB |
Output is correct |
17 |
Correct |
9 ms |
8480 KB |
Output is correct |
18 |
Correct |
9 ms |
8480 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
9 ms |
8144 KB |
Output is correct |
2 |
Correct |
9 ms |
8356 KB |
Output is correct |
3 |
Correct |
8 ms |
8356 KB |
Output is correct |
4 |
Correct |
7 ms |
8356 KB |
Output is correct |
5 |
Correct |
7 ms |
8356 KB |
Output is correct |
6 |
Correct |
8 ms |
8356 KB |
Output is correct |
7 |
Correct |
7 ms |
8356 KB |
Output is correct |
8 |
Correct |
7 ms |
8392 KB |
Output is correct |
9 |
Correct |
8 ms |
8392 KB |
Output is correct |
10 |
Correct |
8 ms |
8392 KB |
Output is correct |
11 |
Correct |
7 ms |
8392 KB |
Output is correct |
12 |
Correct |
9 ms |
8392 KB |
Output is correct |
13 |
Correct |
9 ms |
8400 KB |
Output is correct |
14 |
Correct |
9 ms |
8480 KB |
Output is correct |
15 |
Correct |
8 ms |
8480 KB |
Output is correct |
16 |
Correct |
9 ms |
8480 KB |
Output is correct |
17 |
Correct |
9 ms |
8480 KB |
Output is correct |
18 |
Correct |
9 ms |
8480 KB |
Output is correct |
19 |
Correct |
10 ms |
8480 KB |
Output is correct |
20 |
Correct |
7 ms |
8480 KB |
Output is correct |
21 |
Correct |
10 ms |
8548 KB |
Output is correct |
22 |
Correct |
9 ms |
8548 KB |
Output is correct |
23 |
Correct |
9 ms |
8548 KB |
Output is correct |
24 |
Correct |
10 ms |
8548 KB |
Output is correct |
25 |
Correct |
10 ms |
8548 KB |
Output is correct |
26 |
Correct |
9 ms |
8664 KB |
Output is correct |
27 |
Correct |
8 ms |
8664 KB |
Output is correct |
28 |
Correct |
9 ms |
8664 KB |
Output is correct |
29 |
Correct |
9 ms |
8664 KB |
Output is correct |
30 |
Correct |
9 ms |
8664 KB |
Output is correct |
31 |
Correct |
10 ms |
8664 KB |
Output is correct |
32 |
Correct |
13 ms |
8664 KB |
Output is correct |
33 |
Correct |
10 ms |
8664 KB |
Output is correct |
34 |
Correct |
10 ms |
8664 KB |
Output is correct |
35 |
Correct |
9 ms |
8664 KB |
Output is correct |
36 |
Correct |
10 ms |
8664 KB |
Output is correct |
37 |
Correct |
10 ms |
8664 KB |
Output is correct |
38 |
Correct |
11 ms |
8664 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
9 ms |
8144 KB |
Output is correct |
2 |
Correct |
9 ms |
8356 KB |
Output is correct |
3 |
Correct |
8 ms |
8356 KB |
Output is correct |
4 |
Correct |
7 ms |
8356 KB |
Output is correct |
5 |
Correct |
7 ms |
8356 KB |
Output is correct |
6 |
Correct |
8 ms |
8356 KB |
Output is correct |
7 |
Correct |
7 ms |
8356 KB |
Output is correct |
8 |
Correct |
7 ms |
8392 KB |
Output is correct |
9 |
Correct |
8 ms |
8392 KB |
Output is correct |
10 |
Correct |
8 ms |
8392 KB |
Output is correct |
11 |
Correct |
7 ms |
8392 KB |
Output is correct |
12 |
Correct |
9 ms |
8392 KB |
Output is correct |
13 |
Correct |
9 ms |
8400 KB |
Output is correct |
14 |
Correct |
9 ms |
8480 KB |
Output is correct |
15 |
Correct |
8 ms |
8480 KB |
Output is correct |
16 |
Correct |
9 ms |
8480 KB |
Output is correct |
17 |
Correct |
9 ms |
8480 KB |
Output is correct |
18 |
Correct |
9 ms |
8480 KB |
Output is correct |
19 |
Correct |
316 ms |
17676 KB |
Output is correct |
20 |
Correct |
325 ms |
17676 KB |
Output is correct |
21 |
Correct |
342 ms |
17724 KB |
Output is correct |
22 |
Correct |
321 ms |
17908 KB |
Output is correct |
23 |
Correct |
271 ms |
18040 KB |
Output is correct |
24 |
Correct |
210 ms |
18040 KB |
Output is correct |
25 |
Correct |
346 ms |
18040 KB |
Output is correct |
26 |
Correct |
208 ms |
18520 KB |
Output is correct |
27 |
Correct |
405 ms |
26360 KB |
Output is correct |
28 |
Correct |
705 ms |
26508 KB |
Output is correct |
29 |
Correct |
678 ms |
26512 KB |
Output is correct |
30 |
Correct |
529 ms |
26512 KB |
Output is correct |
31 |
Correct |
397 ms |
26512 KB |
Output is correct |
32 |
Correct |
554 ms |
26512 KB |
Output is correct |
33 |
Correct |
815 ms |
26512 KB |
Output is correct |
34 |
Correct |
829 ms |
26512 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
9 ms |
8144 KB |
Output is correct |
2 |
Correct |
9 ms |
8356 KB |
Output is correct |
3 |
Correct |
8 ms |
8356 KB |
Output is correct |
4 |
Correct |
7 ms |
8356 KB |
Output is correct |
5 |
Correct |
7 ms |
8356 KB |
Output is correct |
6 |
Correct |
8 ms |
8356 KB |
Output is correct |
7 |
Correct |
7 ms |
8356 KB |
Output is correct |
8 |
Correct |
7 ms |
8392 KB |
Output is correct |
9 |
Correct |
8 ms |
8392 KB |
Output is correct |
10 |
Correct |
8 ms |
8392 KB |
Output is correct |
11 |
Correct |
7 ms |
8392 KB |
Output is correct |
12 |
Correct |
9 ms |
8392 KB |
Output is correct |
13 |
Correct |
9 ms |
8400 KB |
Output is correct |
14 |
Correct |
9 ms |
8480 KB |
Output is correct |
15 |
Correct |
8 ms |
8480 KB |
Output is correct |
16 |
Correct |
9 ms |
8480 KB |
Output is correct |
17 |
Correct |
9 ms |
8480 KB |
Output is correct |
18 |
Correct |
9 ms |
8480 KB |
Output is correct |
19 |
Correct |
10 ms |
8480 KB |
Output is correct |
20 |
Correct |
7 ms |
8480 KB |
Output is correct |
21 |
Correct |
10 ms |
8548 KB |
Output is correct |
22 |
Correct |
9 ms |
8548 KB |
Output is correct |
23 |
Correct |
9 ms |
8548 KB |
Output is correct |
24 |
Correct |
10 ms |
8548 KB |
Output is correct |
25 |
Correct |
10 ms |
8548 KB |
Output is correct |
26 |
Correct |
9 ms |
8664 KB |
Output is correct |
27 |
Correct |
8 ms |
8664 KB |
Output is correct |
28 |
Correct |
9 ms |
8664 KB |
Output is correct |
29 |
Correct |
9 ms |
8664 KB |
Output is correct |
30 |
Correct |
9 ms |
8664 KB |
Output is correct |
31 |
Correct |
10 ms |
8664 KB |
Output is correct |
32 |
Correct |
13 ms |
8664 KB |
Output is correct |
33 |
Correct |
10 ms |
8664 KB |
Output is correct |
34 |
Correct |
10 ms |
8664 KB |
Output is correct |
35 |
Correct |
9 ms |
8664 KB |
Output is correct |
36 |
Correct |
10 ms |
8664 KB |
Output is correct |
37 |
Correct |
10 ms |
8664 KB |
Output is correct |
38 |
Correct |
11 ms |
8664 KB |
Output is correct |
39 |
Correct |
316 ms |
17676 KB |
Output is correct |
40 |
Correct |
325 ms |
17676 KB |
Output is correct |
41 |
Correct |
342 ms |
17724 KB |
Output is correct |
42 |
Correct |
321 ms |
17908 KB |
Output is correct |
43 |
Correct |
271 ms |
18040 KB |
Output is correct |
44 |
Correct |
210 ms |
18040 KB |
Output is correct |
45 |
Correct |
346 ms |
18040 KB |
Output is correct |
46 |
Correct |
208 ms |
18520 KB |
Output is correct |
47 |
Correct |
405 ms |
26360 KB |
Output is correct |
48 |
Correct |
705 ms |
26508 KB |
Output is correct |
49 |
Correct |
678 ms |
26512 KB |
Output is correct |
50 |
Correct |
529 ms |
26512 KB |
Output is correct |
51 |
Correct |
397 ms |
26512 KB |
Output is correct |
52 |
Correct |
554 ms |
26512 KB |
Output is correct |
53 |
Correct |
815 ms |
26512 KB |
Output is correct |
54 |
Correct |
829 ms |
26512 KB |
Output is correct |
55 |
Correct |
29 ms |
26512 KB |
Output is correct |
56 |
Correct |
33 ms |
26512 KB |
Output is correct |
57 |
Correct |
240 ms |
26512 KB |
Output is correct |
58 |
Incorrect |
95 ms |
26512 KB |
Output isn't correct |
59 |
Halted |
0 ms |
0 KB |
- |