Submission #7710

# Submission time Handle Problem Language Result Execution time Memory
7710 2014-08-15T10:26:02 Z baneling100 Race (IOI11_race) C++
100 / 100
891 ms 37448 KB
#include "race.h"
#include <algorithm>
#include <vector>
#include <queue>
#define INF 0x7fffffff

using namespace std;

typedef pair <int,int> ppair;
static vector <ppair> A[200000];
static vector <ppair> Length;
static vector <int> Eraser;
static int N, K, Die[200000], Check[200000], D[1000001];
static int Num, Center, Ans=INF;

int HowManyNode(int Now) {

    int i, j=A[Now].size(), Temp=1;

    Check[Now]=1;
    for(i=0 ; i<j ; i++)
        if(!Die[A[Now][i].first] && !Check[A[Now][i].first])
            Temp+=HowManyNode(A[Now][i].first);
    Check[Now]=0;
    return Temp;
}

int FindCenter(int Now) {

    int i, j=A[Now].size(), OK=1, Sum=1, Temp;

    Check[Now]=1;
    for(i=0 ; i<j ; i++)
        if(!Die[A[Now][i].first] && !Check[A[Now][i].first]) {
            Temp=FindCenter(A[Now][i].first);
            Sum+=Temp;
            if(Temp>Num/2)
                OK=0;
        }
    Check[Now]=0;
    if(Num-Sum>Num/2)
        OK=0;
    if(OK)
        Center=Now;
    return Sum;
}

void FindLength(int Now, int Len, int Lev) {

    int i, j=A[Now].size();

    Check[Now]=1;
    if(Len<=K)
        Length.push_back(make_pair(Len,Lev));
    for(i=0 ; i<j ; i++)
        if(!Die[A[Now][i].first] && !Check[A[Now][i].first])
            FindLength(A[Now][i].first,Len+A[Now][i].second,Lev+1);
    Check[Now]=0;
}

void DivideConquer(int Route) {

    int i, j=A[Route].size(), k, l, Temp;

    Eraser.clear();
    for(i=0 ; i<j ; i++)
        if(!Die[A[Route][i].first]) {
            Length.clear();
            FindLength(A[Route][i].first,A[Route][i].second,1);
            l=Length.size();
            for(k=0 ; k<l ; k++)
                if(D[K-Length[k].first] || Length[k].first==K)
                    if(Ans>Length[k].second+D[K-Length[k].first])
                        Ans=Length[k].second+D[K-Length[k].first];
            for(k=0 ; k<l ; k++) {
                if(!D[Length[k].first]) {
                    Eraser.push_back(Length[k].first);
                    D[Length[k].first]=Length[k].second;
                }
                else if(D[Length[k].first]>Length[k].second)
                    D[Length[k].first]=Length[k].second;
            }
        }
    l=Eraser.size();
    for(k=0 ; k<l ; k++)
        D[Eraser[k]]=0;
    for(i=0 ; i<j ; i++)
        if(!Die[A[Route][i].first]) {
            Num=HowManyNode(A[Route][i].first);
            Temp=FindCenter(A[Route][i].first);
            Die[Center]=1;
            DivideConquer(Center);
        }
}

int best_path(int N_, int K_, int H[][2], int L[]) {

    int i, Temp;

    N=N_;
    K=K_;
    for(i=0 ; i<N-1 ; i++) {
        A[H[i][0]].push_back(make_pair(H[i][1],L[i]));
        A[H[i][1]].push_back(make_pair(H[i][0],L[i]));
    }
    Num=HowManyNode(0);
    Temp=FindCenter(0);
    Die[Center]=1;
    DivideConquer(Center);
    if(Ans==INF)
        return -1;
    return Ans;
}

Compilation message

race.cpp: In function 'void DivideConquer(int)':
race.cpp:63:37: warning: variable 'Temp' set but not used [-Wunused-but-set-variable]
     int i, j=A[Route].size(), k, l, Temp;
                                     ^~~~
race.cpp: In function 'int best_path(int, int, int (*)[2], int*)':
race.cpp:98:12: warning: variable 'Temp' set but not used [-Wunused-but-set-variable]
     int i, Temp;
            ^~~~
# Verdict Execution time Memory Grader output
1 Correct 7 ms 4984 KB Output is correct
2 Correct 6 ms 5224 KB Output is correct
3 Correct 6 ms 5224 KB Output is correct
4 Correct 6 ms 5224 KB Output is correct
5 Correct 7 ms 5324 KB Output is correct
6 Correct 6 ms 5324 KB Output is correct
7 Correct 6 ms 5324 KB Output is correct
8 Correct 6 ms 5324 KB Output is correct
9 Correct 5 ms 5324 KB Output is correct
10 Correct 7 ms 5332 KB Output is correct
11 Correct 7 ms 5332 KB Output is correct
12 Correct 7 ms 5332 KB Output is correct
13 Correct 7 ms 5348 KB Output is correct
14 Correct 6 ms 5348 KB Output is correct
15 Correct 5 ms 5348 KB Output is correct
16 Correct 6 ms 5348 KB Output is correct
17 Correct 7 ms 5348 KB Output is correct
18 Correct 5 ms 5348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 7 ms 4984 KB Output is correct
2 Correct 6 ms 5224 KB Output is correct
3 Correct 6 ms 5224 KB Output is correct
4 Correct 6 ms 5224 KB Output is correct
5 Correct 7 ms 5324 KB Output is correct
6 Correct 6 ms 5324 KB Output is correct
7 Correct 6 ms 5324 KB Output is correct
8 Correct 6 ms 5324 KB Output is correct
9 Correct 5 ms 5324 KB Output is correct
10 Correct 7 ms 5332 KB Output is correct
11 Correct 7 ms 5332 KB Output is correct
12 Correct 7 ms 5332 KB Output is correct
13 Correct 7 ms 5348 KB Output is correct
14 Correct 6 ms 5348 KB Output is correct
15 Correct 5 ms 5348 KB Output is correct
16 Correct 6 ms 5348 KB Output is correct
17 Correct 7 ms 5348 KB Output is correct
18 Correct 5 ms 5348 KB Output is correct
19 Correct 5 ms 5348 KB Output is correct
20 Correct 6 ms 5356 KB Output is correct
21 Correct 6 ms 5372 KB Output is correct
22 Correct 10 ms 7804 KB Output is correct
23 Correct 9 ms 7804 KB Output is correct
24 Correct 11 ms 8188 KB Output is correct
25 Correct 9 ms 8188 KB Output is correct
26 Correct 8 ms 8188 KB Output is correct
27 Correct 6 ms 8188 KB Output is correct
28 Correct 7 ms 8188 KB Output is correct
29 Correct 8 ms 8188 KB Output is correct
30 Correct 9 ms 8188 KB Output is correct
31 Correct 9 ms 8188 KB Output is correct
32 Correct 10 ms 8188 KB Output is correct
33 Correct 11 ms 8188 KB Output is correct
34 Correct 9 ms 8188 KB Output is correct
35 Correct 10 ms 8316 KB Output is correct
36 Correct 11 ms 8572 KB Output is correct
37 Correct 9 ms 8572 KB Output is correct
38 Correct 8 ms 8572 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 7 ms 4984 KB Output is correct
2 Correct 6 ms 5224 KB Output is correct
3 Correct 6 ms 5224 KB Output is correct
4 Correct 6 ms 5224 KB Output is correct
5 Correct 7 ms 5324 KB Output is correct
6 Correct 6 ms 5324 KB Output is correct
7 Correct 6 ms 5324 KB Output is correct
8 Correct 6 ms 5324 KB Output is correct
9 Correct 5 ms 5324 KB Output is correct
10 Correct 7 ms 5332 KB Output is correct
11 Correct 7 ms 5332 KB Output is correct
12 Correct 7 ms 5332 KB Output is correct
13 Correct 7 ms 5348 KB Output is correct
14 Correct 6 ms 5348 KB Output is correct
15 Correct 5 ms 5348 KB Output is correct
16 Correct 6 ms 5348 KB Output is correct
17 Correct 7 ms 5348 KB Output is correct
18 Correct 5 ms 5348 KB Output is correct
19 Correct 243 ms 11132 KB Output is correct
20 Correct 271 ms 11132 KB Output is correct
21 Correct 231 ms 11264 KB Output is correct
22 Correct 228 ms 11340 KB Output is correct
23 Correct 213 ms 11340 KB Output is correct
24 Correct 93 ms 11340 KB Output is correct
25 Correct 248 ms 15356 KB Output is correct
26 Correct 136 ms 20260 KB Output is correct
27 Correct 280 ms 20260 KB Output is correct
28 Correct 776 ms 34216 KB Output is correct
29 Correct 874 ms 34216 KB Output is correct
30 Correct 274 ms 34216 KB Output is correct
31 Correct 307 ms 34216 KB Output is correct
32 Correct 400 ms 34216 KB Output is correct
33 Correct 671 ms 34216 KB Output is correct
34 Correct 656 ms 34216 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 7 ms 4984 KB Output is correct
2 Correct 6 ms 5224 KB Output is correct
3 Correct 6 ms 5224 KB Output is correct
4 Correct 6 ms 5224 KB Output is correct
5 Correct 7 ms 5324 KB Output is correct
6 Correct 6 ms 5324 KB Output is correct
7 Correct 6 ms 5324 KB Output is correct
8 Correct 6 ms 5324 KB Output is correct
9 Correct 5 ms 5324 KB Output is correct
10 Correct 7 ms 5332 KB Output is correct
11 Correct 7 ms 5332 KB Output is correct
12 Correct 7 ms 5332 KB Output is correct
13 Correct 7 ms 5348 KB Output is correct
14 Correct 6 ms 5348 KB Output is correct
15 Correct 5 ms 5348 KB Output is correct
16 Correct 6 ms 5348 KB Output is correct
17 Correct 7 ms 5348 KB Output is correct
18 Correct 5 ms 5348 KB Output is correct
19 Correct 5 ms 5348 KB Output is correct
20 Correct 6 ms 5356 KB Output is correct
21 Correct 6 ms 5372 KB Output is correct
22 Correct 10 ms 7804 KB Output is correct
23 Correct 9 ms 7804 KB Output is correct
24 Correct 11 ms 8188 KB Output is correct
25 Correct 9 ms 8188 KB Output is correct
26 Correct 8 ms 8188 KB Output is correct
27 Correct 6 ms 8188 KB Output is correct
28 Correct 7 ms 8188 KB Output is correct
29 Correct 8 ms 8188 KB Output is correct
30 Correct 9 ms 8188 KB Output is correct
31 Correct 9 ms 8188 KB Output is correct
32 Correct 10 ms 8188 KB Output is correct
33 Correct 11 ms 8188 KB Output is correct
34 Correct 9 ms 8188 KB Output is correct
35 Correct 10 ms 8316 KB Output is correct
36 Correct 11 ms 8572 KB Output is correct
37 Correct 9 ms 8572 KB Output is correct
38 Correct 8 ms 8572 KB Output is correct
39 Correct 243 ms 11132 KB Output is correct
40 Correct 271 ms 11132 KB Output is correct
41 Correct 231 ms 11264 KB Output is correct
42 Correct 228 ms 11340 KB Output is correct
43 Correct 213 ms 11340 KB Output is correct
44 Correct 93 ms 11340 KB Output is correct
45 Correct 248 ms 15356 KB Output is correct
46 Correct 136 ms 20260 KB Output is correct
47 Correct 280 ms 20260 KB Output is correct
48 Correct 776 ms 34216 KB Output is correct
49 Correct 874 ms 34216 KB Output is correct
50 Correct 274 ms 34216 KB Output is correct
51 Correct 307 ms 34216 KB Output is correct
52 Correct 400 ms 34216 KB Output is correct
53 Correct 671 ms 34216 KB Output is correct
54 Correct 656 ms 34216 KB Output is correct
55 Correct 21 ms 34216 KB Output is correct
56 Correct 19 ms 34216 KB Output is correct
57 Correct 120 ms 34216 KB Output is correct
58 Correct 53 ms 34216 KB Output is correct
59 Correct 149 ms 34216 KB Output is correct
60 Correct 690 ms 37448 KB Output is correct
61 Correct 375 ms 37448 KB Output is correct
62 Correct 341 ms 37448 KB Output is correct
63 Correct 434 ms 37448 KB Output is correct
64 Correct 762 ms 37448 KB Output is correct
65 Correct 604 ms 37448 KB Output is correct
66 Correct 891 ms 37448 KB Output is correct
67 Correct 170 ms 37448 KB Output is correct
68 Correct 420 ms 37448 KB Output is correct
69 Correct 393 ms 37448 KB Output is correct
70 Correct 362 ms 37448 KB Output is correct