답안 #297204

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
297204 2020-09-11T11:04:40 Z alexandra_udristoiu 경주 (Race) (IOI11_race) C++14
100 / 100
704 ms 97500 KB
#include "race.h"
#include<vector>
#include<algorithm>
#define DIM 200005
#define f first
#define s second
using namespace std;
int viz[DIM], num[DIM], d[1000005];
vector< pair<int, int> > v[DIM];
struct str{
    int nod, d, dist, tf;
};
vector<str> w[DIM];
void dfs1(int nod, int t){
    num[nod] = 1;
    for(int i = 0; i < v[nod].size(); i++){
        int vecin = v[nod][i].f;
        if(vecin != t && viz[vecin] == 0){
            dfs1(vecin, nod);
            num[nod] += num[vecin];
        }
    }
}
int findcen(int nod, int t, int k){
    for(int i = 0; i < v[nod].size(); i++){
        int vecin = v[nod][i].f;
        if(vecin != t && viz[vecin] == 0){
            if(num[vecin] > k / 2){
                return findcen(vecin, nod, k);
            }
        }
    }
    return nod;
}
void dfs(int nod, int t, int cen, int d, int dist, int fiu){
    w[cen].push_back( {nod, d, dist, fiu} );
    for(int i = 0; i < v[nod].size(); i++){
        int vecin = v[nod][i].f;
        if(vecin != t && viz[vecin] == 0){
            int ndist = min(10000000, dist + v[nod][i].s);
            dfs(vecin, nod, cen, d + 1, ndist, fiu);
        }
    }
}
void decomp(int nod){
    int x, i, vecin;
    dfs1(nod, -1);
    x = findcen(nod, -1, num[nod]);
    viz[x] = 1;
    for(i = 0; i < v[x].size(); i++){
        vecin = v[x][i].f;
        if(viz[vecin] == 0){
            dfs(vecin, x, x, 1, v[x][i].s, vecin);
        }
    }
    for(i = 0; i < v[x].size(); i++){
        vecin = v[x][i].f;
        if(viz[vecin] == 0){
            decomp(vecin);
        }
    }
}

int best_path(int n, int k, int h[][2], int lg[]){
    int i, j, x, y, sol, ii;
    for(i = 0; i < n - 1; i++){
        x = h[i][0];
        y = h[i][1];
        v[x].push_back( make_pair(y, lg[i]) );
        v[y].push_back( make_pair(x, lg[i]) );
    }
    decomp(0);
    for(i = 1; i <= k; i++){
        d[i] = n;
    }
    sol = n;
    for(i = 0; i < n; i++){
        d[0] = 0;
        for(j = 0; j < w[i].size(); j++){
            for(ii = j; ii < w[i].size(); ii++){
                if(w[i][j].tf != w[i][ii].tf){
                    break;
                }
                if(w[i][ii].dist <= k){
                    sol = min(sol, w[i][ii].d + d[ k - w[i][ii].dist ]);
                }
            }
            for(ii = j; ii < w[i].size(); ii++){
                if(w[i][j].tf != w[i][ii].tf){
                    break;
                }
                if(w[i][ii].dist <= k){
                    d[ w[i][ii].dist ] = min(d[ w[i][ii].dist ], w[i][ii].d);
                }
            }
            j = ii - 1;
        }
        for(j = 0; j < w[i].size(); j++){
            if(w[i][j].dist <= k){
                d[ w[i][j].dist ] = n;
            }
        }
    }
    if(sol == n){
        return -1;
    }
    return sol;
}

Compilation message

race.cpp: In function 'void dfs1(int, int)':
race.cpp:16:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   16 |     for(int i = 0; i < v[nod].size(); i++){
      |                    ~~^~~~~~~~~~~~~~~
race.cpp: In function 'int findcen(int, int, int)':
race.cpp:25:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   25 |     for(int i = 0; i < v[nod].size(); i++){
      |                    ~~^~~~~~~~~~~~~~~
race.cpp: In function 'void dfs(int, int, int, int, int, int)':
race.cpp:37:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   37 |     for(int i = 0; i < v[nod].size(); i++){
      |                    ~~^~~~~~~~~~~~~~~
race.cpp: In function 'void decomp(int)':
race.cpp:50:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   50 |     for(i = 0; i < v[x].size(); i++){
      |                ~~^~~~~~~~~~~~~
race.cpp:56:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   56 |     for(i = 0; i < v[x].size(); i++){
      |                ~~^~~~~~~~~~~~~
race.cpp: In function 'int best_path(int, int, int (*)[2], int*)':
race.cpp:79:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<str>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   79 |         for(j = 0; j < w[i].size(); j++){
      |                    ~~^~~~~~~~~~~~~
race.cpp:80:28: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<str>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   80 |             for(ii = j; ii < w[i].size(); ii++){
      |                         ~~~^~~~~~~~~~~~~
race.cpp:88:28: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<str>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   88 |             for(ii = j; ii < w[i].size(); ii++){
      |                         ~~~^~~~~~~~~~~~~
race.cpp:98:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<str>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   98 |         for(j = 0; j < w[i].size(); j++){
      |                    ~~^~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 9856 KB Output is correct
2 Correct 7 ms 9856 KB Output is correct
3 Correct 7 ms 9728 KB Output is correct
4 Correct 7 ms 9728 KB Output is correct
5 Correct 7 ms 9856 KB Output is correct
6 Correct 7 ms 9728 KB Output is correct
7 Correct 7 ms 9728 KB Output is correct
8 Correct 7 ms 9728 KB Output is correct
9 Correct 7 ms 9728 KB Output is correct
10 Correct 7 ms 9728 KB Output is correct
11 Correct 7 ms 9728 KB Output is correct
12 Correct 7 ms 9728 KB Output is correct
13 Correct 7 ms 9728 KB Output is correct
14 Correct 7 ms 9728 KB Output is correct
15 Correct 7 ms 9728 KB Output is correct
16 Correct 7 ms 9728 KB Output is correct
17 Correct 8 ms 9728 KB Output is correct
18 Correct 7 ms 9728 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 9856 KB Output is correct
2 Correct 7 ms 9856 KB Output is correct
3 Correct 7 ms 9728 KB Output is correct
4 Correct 7 ms 9728 KB Output is correct
5 Correct 7 ms 9856 KB Output is correct
6 Correct 7 ms 9728 KB Output is correct
7 Correct 7 ms 9728 KB Output is correct
8 Correct 7 ms 9728 KB Output is correct
9 Correct 7 ms 9728 KB Output is correct
10 Correct 7 ms 9728 KB Output is correct
11 Correct 7 ms 9728 KB Output is correct
12 Correct 7 ms 9728 KB Output is correct
13 Correct 7 ms 9728 KB Output is correct
14 Correct 7 ms 9728 KB Output is correct
15 Correct 7 ms 9728 KB Output is correct
16 Correct 7 ms 9728 KB Output is correct
17 Correct 8 ms 9728 KB Output is correct
18 Correct 7 ms 9728 KB Output is correct
19 Correct 7 ms 9728 KB Output is correct
20 Correct 7 ms 9728 KB Output is correct
21 Correct 8 ms 9856 KB Output is correct
22 Correct 10 ms 13440 KB Output is correct
23 Correct 10 ms 12800 KB Output is correct
24 Correct 11 ms 13312 KB Output is correct
25 Correct 10 ms 13184 KB Output is correct
26 Correct 10 ms 11136 KB Output is correct
27 Correct 10 ms 13056 KB Output is correct
28 Correct 9 ms 10752 KB Output is correct
29 Correct 9 ms 11136 KB Output is correct
30 Correct 9 ms 11392 KB Output is correct
31 Correct 10 ms 12416 KB Output is correct
32 Correct 11 ms 12672 KB Output is correct
33 Correct 10 ms 12928 KB Output is correct
34 Correct 9 ms 12416 KB Output is correct
35 Correct 10 ms 13056 KB Output is correct
36 Correct 10 ms 13568 KB Output is correct
37 Correct 10 ms 13056 KB Output is correct
38 Correct 9 ms 11904 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 9856 KB Output is correct
2 Correct 7 ms 9856 KB Output is correct
3 Correct 7 ms 9728 KB Output is correct
4 Correct 7 ms 9728 KB Output is correct
5 Correct 7 ms 9856 KB Output is correct
6 Correct 7 ms 9728 KB Output is correct
7 Correct 7 ms 9728 KB Output is correct
8 Correct 7 ms 9728 KB Output is correct
9 Correct 7 ms 9728 KB Output is correct
10 Correct 7 ms 9728 KB Output is correct
11 Correct 7 ms 9728 KB Output is correct
12 Correct 7 ms 9728 KB Output is correct
13 Correct 7 ms 9728 KB Output is correct
14 Correct 7 ms 9728 KB Output is correct
15 Correct 7 ms 9728 KB Output is correct
16 Correct 7 ms 9728 KB Output is correct
17 Correct 8 ms 9728 KB Output is correct
18 Correct 7 ms 9728 KB Output is correct
19 Correct 243 ms 34792 KB Output is correct
20 Correct 241 ms 34796 KB Output is correct
21 Correct 236 ms 34560 KB Output is correct
22 Correct 210 ms 31748 KB Output is correct
23 Correct 197 ms 39016 KB Output is correct
24 Correct 111 ms 26216 KB Output is correct
25 Correct 239 ms 49384 KB Output is correct
26 Correct 151 ms 50148 KB Output is correct
27 Correct 303 ms 43488 KB Output is correct
28 Correct 671 ms 94048 KB Output is correct
29 Correct 679 ms 93276 KB Output is correct
30 Correct 303 ms 43744 KB Output is correct
31 Correct 298 ms 43816 KB Output is correct
32 Correct 410 ms 43608 KB Output is correct
33 Correct 508 ms 72924 KB Output is correct
34 Correct 505 ms 70668 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 9856 KB Output is correct
2 Correct 7 ms 9856 KB Output is correct
3 Correct 7 ms 9728 KB Output is correct
4 Correct 7 ms 9728 KB Output is correct
5 Correct 7 ms 9856 KB Output is correct
6 Correct 7 ms 9728 KB Output is correct
7 Correct 7 ms 9728 KB Output is correct
8 Correct 7 ms 9728 KB Output is correct
9 Correct 7 ms 9728 KB Output is correct
10 Correct 7 ms 9728 KB Output is correct
11 Correct 7 ms 9728 KB Output is correct
12 Correct 7 ms 9728 KB Output is correct
13 Correct 7 ms 9728 KB Output is correct
14 Correct 7 ms 9728 KB Output is correct
15 Correct 7 ms 9728 KB Output is correct
16 Correct 7 ms 9728 KB Output is correct
17 Correct 8 ms 9728 KB Output is correct
18 Correct 7 ms 9728 KB Output is correct
19 Correct 7 ms 9728 KB Output is correct
20 Correct 7 ms 9728 KB Output is correct
21 Correct 8 ms 9856 KB Output is correct
22 Correct 10 ms 13440 KB Output is correct
23 Correct 10 ms 12800 KB Output is correct
24 Correct 11 ms 13312 KB Output is correct
25 Correct 10 ms 13184 KB Output is correct
26 Correct 10 ms 11136 KB Output is correct
27 Correct 10 ms 13056 KB Output is correct
28 Correct 9 ms 10752 KB Output is correct
29 Correct 9 ms 11136 KB Output is correct
30 Correct 9 ms 11392 KB Output is correct
31 Correct 10 ms 12416 KB Output is correct
32 Correct 11 ms 12672 KB Output is correct
33 Correct 10 ms 12928 KB Output is correct
34 Correct 9 ms 12416 KB Output is correct
35 Correct 10 ms 13056 KB Output is correct
36 Correct 10 ms 13568 KB Output is correct
37 Correct 10 ms 13056 KB Output is correct
38 Correct 9 ms 11904 KB Output is correct
39 Correct 243 ms 34792 KB Output is correct
40 Correct 241 ms 34796 KB Output is correct
41 Correct 236 ms 34560 KB Output is correct
42 Correct 210 ms 31748 KB Output is correct
43 Correct 197 ms 39016 KB Output is correct
44 Correct 111 ms 26216 KB Output is correct
45 Correct 239 ms 49384 KB Output is correct
46 Correct 151 ms 50148 KB Output is correct
47 Correct 303 ms 43488 KB Output is correct
48 Correct 671 ms 94048 KB Output is correct
49 Correct 679 ms 93276 KB Output is correct
50 Correct 303 ms 43744 KB Output is correct
51 Correct 298 ms 43816 KB Output is correct
52 Correct 410 ms 43608 KB Output is correct
53 Correct 508 ms 72924 KB Output is correct
54 Correct 505 ms 70668 KB Output is correct
55 Correct 19 ms 11776 KB Output is correct
56 Correct 19 ms 12032 KB Output is correct
57 Correct 139 ms 39396 KB Output is correct
58 Correct 54 ms 17644 KB Output is correct
59 Correct 159 ms 51048 KB Output is correct
60 Correct 672 ms 97500 KB Output is correct
61 Correct 303 ms 43744 KB Output is correct
62 Correct 304 ms 47456 KB Output is correct
63 Correct 408 ms 47448 KB Output is correct
64 Correct 693 ms 64860 KB Output is correct
65 Correct 567 ms 55136 KB Output is correct
66 Correct 704 ms 96476 KB Output is correct
67 Correct 174 ms 28896 KB Output is correct
68 Correct 394 ms 44508 KB Output is correct
69 Correct 392 ms 44384 KB Output is correct
70 Correct 362 ms 42716 KB Output is correct