Submission #16676

# Submission time Handle Problem Language Result Execution time Memory
16676 2015-09-05T12:32:15 Z suhgyuho_william Race (IOI11_race) C++
21 / 100
3000 ms 13552 KB
#include "race.h"
#include <vector>
#include <queue>
#include <algorithm>
using namespace std;
// frozen

int i,n,k;
int answer = 999999999;
vector<pair<int,int> > edge[200002];
queue<pair<int,int> > q;
int root[1000002],small[1000002];
bool check[200002];

int find_middle(int x){
    return x;
}

void dfs(int v,long long sum,int cnt){
    int i,sizes;
    int nextv,cost;

    if(sum > k) return;
    check[v] = true;
    q.push(make_pair(sum,cnt));

    sizes = edge[v].size();
    for(i=0; i<sizes; i++){
        nextv = edge[v][i].first;
        cost = edge[v][i].second;
        if(check[nextv]) continue;
        dfs(nextv,sum+cost,cnt+1);
    }
    check[v] = false;
}

void race(int x){
    int i,sizes;
    int nextv;
    int tsum,tcnt;
    int v = find_middle(x);

    check[v] = true;
    sizes = edge[v].size();

    root[0] = v;
    small[0] = 0;
    for(i=0; i<sizes; i++){
        nextv = edge[v][i].first;
        if(check[nextv]) continue;
        dfs(nextv,edge[v][i].second,1);

        while(!q.empty()){
            tsum = q.front().first;
            tcnt = q.front().second;
            q.pop();

            if(root[k-tsum] == v && answer > small[k-tsum] + tcnt) answer = small[k-tsum] + tcnt;
        }
        dfs(nextv,edge[v][i].second,1);
        while(!q.empty()){
            tsum = q.front().first;
            tcnt = q.front().second;
            q.pop();

            if(root[tsum] != v){
                root[tsum] = v;
                small[tsum] = tcnt;
            }else if(small[tsum] > tcnt) small[tsum] = tcnt;
        }
    }

    for(i=0; i<sizes; i++){
        nextv = edge[v][i].first;
        if(!check[nextv]) race(nextv);
    }
}

int best_path(int N, int K, int H[][2], int L[])
{
    int i;

    n = N; k = K;
    for(i=0; i<n-1; i++){
        edge[H[i][0]].push_back(make_pair(H[i][1],L[i]));
        edge[H[i][1]].push_back(make_pair(H[i][0],L[i]));
    }
    for(i=0; i<=k; i++) root[i] = -1;

    race(0);

    if(answer == 999999999) answer = -1;
    return answer;
}
# Verdict Execution time Memory Grader output
1 Correct 5 ms 4984 KB Output is correct
2 Correct 5 ms 5092 KB Output is correct
3 Correct 6 ms 5168 KB Output is correct
4 Correct 5 ms 5168 KB Output is correct
5 Correct 5 ms 5168 KB Output is correct
6 Correct 5 ms 5244 KB Output is correct
7 Correct 5 ms 5244 KB Output is correct
8 Correct 6 ms 5244 KB Output is correct
9 Correct 5 ms 5244 KB Output is correct
10 Correct 5 ms 5244 KB Output is correct
11 Correct 5 ms 5244 KB Output is correct
12 Correct 5 ms 5244 KB Output is correct
13 Correct 5 ms 5244 KB Output is correct
14 Correct 5 ms 5244 KB Output is correct
15 Correct 6 ms 5244 KB Output is correct
16 Correct 6 ms 5300 KB Output is correct
17 Correct 6 ms 5300 KB Output is correct
18 Correct 6 ms 5300 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 4984 KB Output is correct
2 Correct 5 ms 5092 KB Output is correct
3 Correct 6 ms 5168 KB Output is correct
4 Correct 5 ms 5168 KB Output is correct
5 Correct 5 ms 5168 KB Output is correct
6 Correct 5 ms 5244 KB Output is correct
7 Correct 5 ms 5244 KB Output is correct
8 Correct 6 ms 5244 KB Output is correct
9 Correct 5 ms 5244 KB Output is correct
10 Correct 5 ms 5244 KB Output is correct
11 Correct 5 ms 5244 KB Output is correct
12 Correct 5 ms 5244 KB Output is correct
13 Correct 5 ms 5244 KB Output is correct
14 Correct 5 ms 5244 KB Output is correct
15 Correct 6 ms 5244 KB Output is correct
16 Correct 6 ms 5300 KB Output is correct
17 Correct 6 ms 5300 KB Output is correct
18 Correct 6 ms 5300 KB Output is correct
19 Correct 6 ms 5312 KB Output is correct
20 Correct 6 ms 5312 KB Output is correct
21 Correct 6 ms 5344 KB Output is correct
22 Correct 11 ms 11492 KB Output is correct
23 Correct 9 ms 11492 KB Output is correct
24 Correct 11 ms 11492 KB Output is correct
25 Correct 11 ms 11492 KB Output is correct
26 Correct 8 ms 11492 KB Output is correct
27 Correct 8 ms 11492 KB Output is correct
28 Correct 8 ms 11492 KB Output is correct
29 Correct 9 ms 11492 KB Output is correct
30 Correct 9 ms 11492 KB Output is correct
31 Correct 11 ms 11492 KB Output is correct
32 Correct 11 ms 11492 KB Output is correct
33 Correct 12 ms 11492 KB Output is correct
34 Correct 10 ms 11492 KB Output is correct
35 Correct 13 ms 11760 KB Output is correct
36 Correct 15 ms 12656 KB Output is correct
37 Correct 17 ms 12656 KB Output is correct
38 Correct 11 ms 12656 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 4984 KB Output is correct
2 Correct 5 ms 5092 KB Output is correct
3 Correct 6 ms 5168 KB Output is correct
4 Correct 5 ms 5168 KB Output is correct
5 Correct 5 ms 5168 KB Output is correct
6 Correct 5 ms 5244 KB Output is correct
7 Correct 5 ms 5244 KB Output is correct
8 Correct 6 ms 5244 KB Output is correct
9 Correct 5 ms 5244 KB Output is correct
10 Correct 5 ms 5244 KB Output is correct
11 Correct 5 ms 5244 KB Output is correct
12 Correct 5 ms 5244 KB Output is correct
13 Correct 5 ms 5244 KB Output is correct
14 Correct 5 ms 5244 KB Output is correct
15 Correct 6 ms 5244 KB Output is correct
16 Correct 6 ms 5300 KB Output is correct
17 Correct 6 ms 5300 KB Output is correct
18 Correct 6 ms 5300 KB Output is correct
19 Correct 219 ms 12656 KB Output is correct
20 Correct 207 ms 12656 KB Output is correct
21 Correct 266 ms 12656 KB Output is correct
22 Correct 177 ms 12656 KB Output is correct
23 Correct 75 ms 12656 KB Output is correct
24 Correct 85 ms 12656 KB Output is correct
25 Execution timed out 3055 ms 13552 KB Time limit exceeded
26 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 5 ms 4984 KB Output is correct
2 Correct 5 ms 5092 KB Output is correct
3 Correct 6 ms 5168 KB Output is correct
4 Correct 5 ms 5168 KB Output is correct
5 Correct 5 ms 5168 KB Output is correct
6 Correct 5 ms 5244 KB Output is correct
7 Correct 5 ms 5244 KB Output is correct
8 Correct 6 ms 5244 KB Output is correct
9 Correct 5 ms 5244 KB Output is correct
10 Correct 5 ms 5244 KB Output is correct
11 Correct 5 ms 5244 KB Output is correct
12 Correct 5 ms 5244 KB Output is correct
13 Correct 5 ms 5244 KB Output is correct
14 Correct 5 ms 5244 KB Output is correct
15 Correct 6 ms 5244 KB Output is correct
16 Correct 6 ms 5300 KB Output is correct
17 Correct 6 ms 5300 KB Output is correct
18 Correct 6 ms 5300 KB Output is correct
19 Correct 6 ms 5312 KB Output is correct
20 Correct 6 ms 5312 KB Output is correct
21 Correct 6 ms 5344 KB Output is correct
22 Correct 11 ms 11492 KB Output is correct
23 Correct 9 ms 11492 KB Output is correct
24 Correct 11 ms 11492 KB Output is correct
25 Correct 11 ms 11492 KB Output is correct
26 Correct 8 ms 11492 KB Output is correct
27 Correct 8 ms 11492 KB Output is correct
28 Correct 8 ms 11492 KB Output is correct
29 Correct 9 ms 11492 KB Output is correct
30 Correct 9 ms 11492 KB Output is correct
31 Correct 11 ms 11492 KB Output is correct
32 Correct 11 ms 11492 KB Output is correct
33 Correct 12 ms 11492 KB Output is correct
34 Correct 10 ms 11492 KB Output is correct
35 Correct 13 ms 11760 KB Output is correct
36 Correct 15 ms 12656 KB Output is correct
37 Correct 17 ms 12656 KB Output is correct
38 Correct 11 ms 12656 KB Output is correct
39 Correct 219 ms 12656 KB Output is correct
40 Correct 207 ms 12656 KB Output is correct
41 Correct 266 ms 12656 KB Output is correct
42 Correct 177 ms 12656 KB Output is correct
43 Correct 75 ms 12656 KB Output is correct
44 Correct 85 ms 12656 KB Output is correct
45 Execution timed out 3055 ms 13552 KB Time limit exceeded
46 Halted 0 ms 0 KB -