# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
14669 |
2015-06-01T14:48:47 Z |
minsu |
Race (IOI11_race) |
C++14 |
|
3000 ms |
13764 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, A[MAXK], size[MAXN], par[MAXN];
int solve(int root){
struct Sres{ int now, nowk, len, iter, par; };
int ret=INF; MS0(A);
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(A[k-it.F]) ret=min(ret, A[k-it.F]+it.S);
for(auto it : paths)
A[it.F]=min( ( A[it.F]==0 ? INF : A[it.F] ), it.S);
} if(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);
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 |
19 ms |
4216 KB |
Output is correct |
2 |
Correct |
17 ms |
4456 KB |
Output is correct |
3 |
Correct |
17 ms |
4456 KB |
Output is correct |
4 |
Correct |
17 ms |
4456 KB |
Output is correct |
5 |
Correct |
19 ms |
4456 KB |
Output is correct |
6 |
Correct |
21 ms |
4464 KB |
Output is correct |
7 |
Correct |
21 ms |
4484 KB |
Output is correct |
8 |
Correct |
21 ms |
4484 KB |
Output is correct |
9 |
Correct |
21 ms |
4532 KB |
Output is correct |
10 |
Correct |
21 ms |
4532 KB |
Output is correct |
11 |
Correct |
21 ms |
4532 KB |
Output is correct |
12 |
Correct |
19 ms |
4532 KB |
Output is correct |
13 |
Correct |
17 ms |
4532 KB |
Output is correct |
14 |
Correct |
17 ms |
4532 KB |
Output is correct |
15 |
Correct |
21 ms |
4540 KB |
Output is correct |
16 |
Correct |
25 ms |
4540 KB |
Output is correct |
17 |
Correct |
23 ms |
4540 KB |
Output is correct |
18 |
Correct |
21 ms |
4540 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
19 ms |
4216 KB |
Output is correct |
2 |
Correct |
17 ms |
4456 KB |
Output is correct |
3 |
Correct |
17 ms |
4456 KB |
Output is correct |
4 |
Correct |
17 ms |
4456 KB |
Output is correct |
5 |
Correct |
19 ms |
4456 KB |
Output is correct |
6 |
Correct |
21 ms |
4464 KB |
Output is correct |
7 |
Correct |
21 ms |
4484 KB |
Output is correct |
8 |
Correct |
21 ms |
4484 KB |
Output is correct |
9 |
Correct |
21 ms |
4532 KB |
Output is correct |
10 |
Correct |
21 ms |
4532 KB |
Output is correct |
11 |
Correct |
21 ms |
4532 KB |
Output is correct |
12 |
Correct |
19 ms |
4532 KB |
Output is correct |
13 |
Correct |
17 ms |
4532 KB |
Output is correct |
14 |
Correct |
17 ms |
4532 KB |
Output is correct |
15 |
Correct |
21 ms |
4540 KB |
Output is correct |
16 |
Correct |
25 ms |
4540 KB |
Output is correct |
17 |
Correct |
23 ms |
4540 KB |
Output is correct |
18 |
Correct |
21 ms |
4540 KB |
Output is correct |
19 |
Correct |
6 ms |
4540 KB |
Output is correct |
20 |
Correct |
14 ms |
4540 KB |
Output is correct |
21 |
Correct |
102 ms |
4616 KB |
Output is correct |
22 |
Correct |
106 ms |
4688 KB |
Output is correct |
23 |
Correct |
96 ms |
4724 KB |
Output is correct |
24 |
Correct |
91 ms |
4732 KB |
Output is correct |
25 |
Correct |
94 ms |
4732 KB |
Output is correct |
26 |
Correct |
91 ms |
4732 KB |
Output is correct |
27 |
Correct |
98 ms |
4732 KB |
Output is correct |
28 |
Correct |
90 ms |
4732 KB |
Output is correct |
29 |
Correct |
95 ms |
4732 KB |
Output is correct |
30 |
Correct |
90 ms |
4732 KB |
Output is correct |
31 |
Correct |
92 ms |
4732 KB |
Output is correct |
32 |
Correct |
105 ms |
4732 KB |
Output is correct |
33 |
Correct |
98 ms |
4732 KB |
Output is correct |
34 |
Correct |
125 ms |
4732 KB |
Output is correct |
35 |
Correct |
112 ms |
4788 KB |
Output is correct |
36 |
Correct |
108 ms |
4788 KB |
Output is correct |
37 |
Correct |
101 ms |
4788 KB |
Output is correct |
38 |
Correct |
111 ms |
4788 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
19 ms |
4216 KB |
Output is correct |
2 |
Correct |
17 ms |
4456 KB |
Output is correct |
3 |
Correct |
17 ms |
4456 KB |
Output is correct |
4 |
Correct |
17 ms |
4456 KB |
Output is correct |
5 |
Correct |
19 ms |
4456 KB |
Output is correct |
6 |
Correct |
21 ms |
4464 KB |
Output is correct |
7 |
Correct |
21 ms |
4484 KB |
Output is correct |
8 |
Correct |
21 ms |
4484 KB |
Output is correct |
9 |
Correct |
21 ms |
4532 KB |
Output is correct |
10 |
Correct |
21 ms |
4532 KB |
Output is correct |
11 |
Correct |
21 ms |
4532 KB |
Output is correct |
12 |
Correct |
19 ms |
4532 KB |
Output is correct |
13 |
Correct |
17 ms |
4532 KB |
Output is correct |
14 |
Correct |
17 ms |
4532 KB |
Output is correct |
15 |
Correct |
21 ms |
4540 KB |
Output is correct |
16 |
Correct |
25 ms |
4540 KB |
Output is correct |
17 |
Correct |
23 ms |
4540 KB |
Output is correct |
18 |
Correct |
21 ms |
4540 KB |
Output is correct |
19 |
Execution timed out |
3069 ms |
13764 KB |
Time limit exceeded |
20 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
19 ms |
4216 KB |
Output is correct |
2 |
Correct |
17 ms |
4456 KB |
Output is correct |
3 |
Correct |
17 ms |
4456 KB |
Output is correct |
4 |
Correct |
17 ms |
4456 KB |
Output is correct |
5 |
Correct |
19 ms |
4456 KB |
Output is correct |
6 |
Correct |
21 ms |
4464 KB |
Output is correct |
7 |
Correct |
21 ms |
4484 KB |
Output is correct |
8 |
Correct |
21 ms |
4484 KB |
Output is correct |
9 |
Correct |
21 ms |
4532 KB |
Output is correct |
10 |
Correct |
21 ms |
4532 KB |
Output is correct |
11 |
Correct |
21 ms |
4532 KB |
Output is correct |
12 |
Correct |
19 ms |
4532 KB |
Output is correct |
13 |
Correct |
17 ms |
4532 KB |
Output is correct |
14 |
Correct |
17 ms |
4532 KB |
Output is correct |
15 |
Correct |
21 ms |
4540 KB |
Output is correct |
16 |
Correct |
25 ms |
4540 KB |
Output is correct |
17 |
Correct |
23 ms |
4540 KB |
Output is correct |
18 |
Correct |
21 ms |
4540 KB |
Output is correct |
19 |
Correct |
6 ms |
4540 KB |
Output is correct |
20 |
Correct |
14 ms |
4540 KB |
Output is correct |
21 |
Correct |
102 ms |
4616 KB |
Output is correct |
22 |
Correct |
106 ms |
4688 KB |
Output is correct |
23 |
Correct |
96 ms |
4724 KB |
Output is correct |
24 |
Correct |
91 ms |
4732 KB |
Output is correct |
25 |
Correct |
94 ms |
4732 KB |
Output is correct |
26 |
Correct |
91 ms |
4732 KB |
Output is correct |
27 |
Correct |
98 ms |
4732 KB |
Output is correct |
28 |
Correct |
90 ms |
4732 KB |
Output is correct |
29 |
Correct |
95 ms |
4732 KB |
Output is correct |
30 |
Correct |
90 ms |
4732 KB |
Output is correct |
31 |
Correct |
92 ms |
4732 KB |
Output is correct |
32 |
Correct |
105 ms |
4732 KB |
Output is correct |
33 |
Correct |
98 ms |
4732 KB |
Output is correct |
34 |
Correct |
125 ms |
4732 KB |
Output is correct |
35 |
Correct |
112 ms |
4788 KB |
Output is correct |
36 |
Correct |
108 ms |
4788 KB |
Output is correct |
37 |
Correct |
101 ms |
4788 KB |
Output is correct |
38 |
Correct |
111 ms |
4788 KB |
Output is correct |
39 |
Execution timed out |
3069 ms |
13764 KB |
Time limit exceeded |
40 |
Halted |
0 ms |
0 KB |
- |