답안 #153811

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
153811 2019-09-16T14:21:13 Z popovicirobert 꿈 (IOI13_dreaming) C++14
47 / 100
171 ms 16372 KB
#include "dreaming.h"
#include <bits/stdc++.h>

using namespace std;

const int INF = 2e9;
const int MAXN = (int) 1e5;

static vector < pair <int, int> > g[MAXN + 1];
static int dstA[MAXN + 1], dstB[MAXN + 1];
static bool vis[MAXN + 1], on_way[MAXN + 1];
static vector <int> nodes;

void dfs(int nod, int par, int *dst) {
    if(vis[nod] == 0) {
        nodes.push_back(nod);
    }
    vis[nod] = 1;
    for(auto it : g[nod]) {
        if(it.first != par) {
            dst[it.first] = dst[nod] + it.second;
            dfs(it.first, nod, dst);
        }
    }
}

int travelTime(int n, int m, int l, int A[], int B[], int T[]) {
    int i;
    for(i = 0; i < m; i++) {
        A[i]++, B[i]++;
        g[A[i]].push_back({B[i], T[i]});
        g[B[i]].push_back({A[i], T[i]});
    }

    int nod = 0, dst = 0, ans = 0;
    for(i = 1; i <= n; i++) {
        if(vis[i]) continue;

        nodes.clear();
        dfs(i, 0, dstA);
        int a = 0;
        for(auto it : nodes) {
            if(dstA[it] >= dstA[a]) {
                a = it;
            }
        }
        dstA[a] = 0;
        dfs(a, 0, dstA);

        int b = 0;
        for(auto it : nodes) {
            if(dstA[it] >= dstA[b]) {
                b = it;
            }
        }
        dfs(b, 0, dstB);

        int cur_nod, cur_dst = INF;
        int id;

        for(auto it : nodes) {
            if(cur_dst >= max(dstA[it], dstB[it])) {
                cur_dst = max(dstA[it], dstB[it]);
                if(cur_dst == dstA[it]) {
                    id = a;
                }
                else {
                    id = b;
                }
                cur_nod = it;
            }
        }

        int aux = cur_nod;
        while(aux != id) {
            on_way[aux] = 1;
            for(auto it : g[aux]) {
                if(id == a) {
                    if(dstA[it.first] + it.second == dstA[aux]) {
                        aux = it.first;
                        break;
                    }
                }
                else {
                    if(dstB[it.first] + it.second == dstB[aux]) {
                        aux = it.first;
                        break;
                    }
                }
            }
        }
        on_way[id] = 1;

        if(ans <= dstA[b] && (i == 1 || dstA[b] >= l + dst + cur_dst)) {
            ans = dstA[b];
            nod = cur_nod;
            dst = cur_dst;
        }
        else if(ans <= l + dst + cur_dst) {
            ans = l + dst + cur_dst;
            cur_dst = dst + l;
            dst = max(dst, ans - dst);

            while(dst > max(cur_dst, ans - cur_dst)) {
                nod = cur_nod;
                dst = max(cur_dst, ans - cur_dst);
                for(auto it : g[nod]) {
                    if(on_way[it.first]) {
                        cur_nod = it.first;
                        cur_dst += it.second;
                        break;
                    }
                }
            }
        }

        /*cerr << ans << " " << dst << " " << nod << "\n";
        for(auto it : nodes) {
            cerr << it << " " << on_way[it] << "\n";
        }
        cerr << "\n";*/

    }
    return ans;
}

Compilation message

dreaming.cpp: In function 'int travelTime(int, int, int, int*, int*, int*)':
dreaming.cpp:78:17: warning: 'id' may be used uninitialized in this function [-Wmaybe-uninitialized]
                 if(id == a) {
                 ^~
dreaming.cpp:92:20: warning: 'cur_nod' may be used uninitialized in this function [-Wmaybe-uninitialized]
         on_way[id] = 1;
         ~~~~~~~~~~~^~~
# 결과 실행 시간 메모리 Grader output
1 Correct 79 ms 13684 KB Output is correct
2 Correct 87 ms 13684 KB Output is correct
3 Correct 51 ms 9972 KB Output is correct
4 Correct 13 ms 4344 KB Output is correct
5 Correct 12 ms 3576 KB Output is correct
6 Correct 21 ms 5240 KB Output is correct
7 Correct 5 ms 2808 KB Output is correct
8 Correct 37 ms 6520 KB Output is correct
9 Correct 49 ms 8156 KB Output is correct
10 Correct 4 ms 2808 KB Output is correct
11 Correct 71 ms 9668 KB Output is correct
12 Correct 96 ms 11632 KB Output is correct
13 Correct 5 ms 2808 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 79 ms 13684 KB Output is correct
2 Correct 87 ms 13684 KB Output is correct
3 Correct 51 ms 9972 KB Output is correct
4 Correct 13 ms 4344 KB Output is correct
5 Correct 12 ms 3576 KB Output is correct
6 Correct 21 ms 5240 KB Output is correct
7 Correct 5 ms 2808 KB Output is correct
8 Correct 37 ms 6520 KB Output is correct
9 Correct 49 ms 8156 KB Output is correct
10 Correct 4 ms 2808 KB Output is correct
11 Correct 71 ms 9668 KB Output is correct
12 Correct 96 ms 11632 KB Output is correct
13 Correct 5 ms 2808 KB Output is correct
14 Correct 4 ms 2684 KB Output is correct
15 Correct 4 ms 2680 KB Output is correct
16 Correct 4 ms 2680 KB Output is correct
17 Correct 4 ms 2680 KB Output is correct
18 Correct 4 ms 2680 KB Output is correct
19 Correct 4 ms 2680 KB Output is correct
20 Correct 4 ms 2680 KB Output is correct
21 Correct 4 ms 2680 KB Output is correct
22 Correct 4 ms 2680 KB Output is correct
23 Correct 4 ms 2680 KB Output is correct
24 Correct 4 ms 2680 KB Output is correct
25 Correct 4 ms 2680 KB Output is correct
26 Correct 4 ms 2680 KB Output is correct
27 Correct 4 ms 2680 KB Output is correct
28 Correct 4 ms 2680 KB Output is correct
29 Correct 5 ms 2680 KB Output is correct
30 Correct 4 ms 2680 KB Output is correct
31 Correct 4 ms 2808 KB Output is correct
32 Correct 4 ms 2684 KB Output is correct
33 Correct 4 ms 2680 KB Output is correct
34 Correct 4 ms 2680 KB Output is correct
35 Correct 4 ms 2680 KB Output is correct
36 Correct 5 ms 2680 KB Output is correct
37 Correct 8 ms 2680 KB Output is correct
38 Correct 4 ms 2680 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 79 ms 13684 KB Output is correct
2 Correct 87 ms 13684 KB Output is correct
3 Correct 51 ms 9972 KB Output is correct
4 Correct 13 ms 4344 KB Output is correct
5 Correct 12 ms 3576 KB Output is correct
6 Correct 21 ms 5240 KB Output is correct
7 Correct 5 ms 2808 KB Output is correct
8 Correct 37 ms 6520 KB Output is correct
9 Correct 49 ms 8156 KB Output is correct
10 Correct 4 ms 2808 KB Output is correct
11 Correct 71 ms 9668 KB Output is correct
12 Correct 96 ms 11632 KB Output is correct
13 Correct 5 ms 2808 KB Output is correct
14 Correct 4 ms 2684 KB Output is correct
15 Correct 4 ms 2680 KB Output is correct
16 Correct 4 ms 2680 KB Output is correct
17 Correct 4 ms 2680 KB Output is correct
18 Correct 4 ms 2680 KB Output is correct
19 Correct 4 ms 2680 KB Output is correct
20 Correct 4 ms 2680 KB Output is correct
21 Correct 4 ms 2680 KB Output is correct
22 Correct 4 ms 2680 KB Output is correct
23 Correct 4 ms 2680 KB Output is correct
24 Correct 4 ms 2680 KB Output is correct
25 Correct 4 ms 2680 KB Output is correct
26 Correct 4 ms 2680 KB Output is correct
27 Correct 4 ms 2680 KB Output is correct
28 Correct 4 ms 2680 KB Output is correct
29 Correct 5 ms 2680 KB Output is correct
30 Correct 4 ms 2680 KB Output is correct
31 Correct 4 ms 2808 KB Output is correct
32 Correct 4 ms 2684 KB Output is correct
33 Correct 4 ms 2680 KB Output is correct
34 Correct 4 ms 2680 KB Output is correct
35 Correct 4 ms 2680 KB Output is correct
36 Correct 5 ms 2680 KB Output is correct
37 Correct 8 ms 2680 KB Output is correct
38 Correct 4 ms 2680 KB Output is correct
39 Correct 96 ms 14912 KB Output is correct
40 Correct 80 ms 15064 KB Output is correct
41 Correct 49 ms 10968 KB Output is correct
42 Correct 13 ms 4600 KB Output is correct
43 Correct 4 ms 2680 KB Output is correct
44 Correct 4 ms 2728 KB Output is correct
45 Correct 4 ms 2680 KB Output is correct
46 Correct 4 ms 2680 KB Output is correct
47 Correct 4 ms 2680 KB Output is correct
48 Correct 5 ms 2680 KB Output is correct
49 Correct 4 ms 2680 KB Output is correct
50 Correct 4 ms 2680 KB Output is correct
51 Correct 4 ms 2684 KB Output is correct
52 Correct 5 ms 2680 KB Output is correct
53 Correct 4 ms 2680 KB Output is correct
54 Correct 4 ms 2680 KB Output is correct
55 Correct 5 ms 2680 KB Output is correct
56 Correct 4 ms 2680 KB Output is correct
57 Correct 155 ms 10768 KB Output is correct
58 Correct 171 ms 10484 KB Output is correct
59 Correct 156 ms 10596 KB Output is correct
60 Correct 111 ms 10404 KB Output is correct
61 Correct 100 ms 10628 KB Output is correct
62 Correct 105 ms 10596 KB Output is correct
63 Correct 103 ms 10296 KB Output is correct
64 Correct 114 ms 10240 KB Output is correct
65 Correct 98 ms 10608 KB Output is correct
66 Correct 93 ms 10612 KB Output is correct
67 Correct 111 ms 10476 KB Output is correct
68 Correct 114 ms 10476 KB Output is correct
69 Correct 121 ms 10880 KB Output is correct
70 Correct 111 ms 10740 KB Output is correct
71 Correct 4 ms 2680 KB Output is correct
72 Correct 6 ms 2936 KB Output is correct
73 Correct 7 ms 2936 KB Output is correct
74 Correct 6 ms 2936 KB Output is correct
75 Correct 6 ms 2936 KB Output is correct
76 Correct 6 ms 2936 KB Output is correct
77 Correct 6 ms 2936 KB Output is correct
78 Correct 5 ms 2908 KB Output is correct
79 Correct 7 ms 2936 KB Output is correct
80 Correct 129 ms 10728 KB Output is correct
81 Correct 122 ms 10512 KB Output is correct
82 Correct 108 ms 10760 KB Output is correct
83 Correct 114 ms 10736 KB Output is correct
84 Correct 6 ms 2936 KB Output is correct
85 Correct 6 ms 2812 KB Output is correct
86 Correct 6 ms 2808 KB Output is correct
87 Correct 6 ms 2936 KB Output is correct
88 Correct 6 ms 2936 KB Output is correct
89 Correct 7 ms 2936 KB Output is correct
90 Correct 7 ms 2936 KB Output is correct
91 Correct 6 ms 2936 KB Output is correct
92 Correct 6 ms 2936 KB Output is correct
93 Correct 6 ms 2936 KB Output is correct
94 Correct 4 ms 2752 KB Output is correct
95 Correct 3 ms 2680 KB Output is correct
96 Correct 4 ms 2680 KB Output is correct
97 Correct 4 ms 2680 KB Output is correct
98 Correct 4 ms 2680 KB Output is correct
99 Correct 5 ms 2680 KB Output is correct
100 Correct 5 ms 2680 KB Output is correct
101 Correct 5 ms 2684 KB Output is correct
102 Correct 6 ms 2680 KB Output is correct
103 Correct 5 ms 2680 KB Output is correct
104 Correct 13 ms 3576 KB Output is correct
105 Correct 23 ms 5508 KB Output is correct
106 Correct 4 ms 2808 KB Output is correct
107 Correct 37 ms 7032 KB Output is correct
108 Correct 51 ms 8952 KB Output is correct
109 Correct 5 ms 2808 KB Output is correct
110 Correct 77 ms 10872 KB Output is correct
111 Correct 111 ms 12756 KB Output is correct
112 Correct 5 ms 2808 KB Output is correct
113 Correct 152 ms 16372 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 33 ms 6392 KB Output is correct
2 Incorrect 36 ms 6440 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 79 ms 13684 KB Output is correct
2 Correct 87 ms 13684 KB Output is correct
3 Correct 51 ms 9972 KB Output is correct
4 Correct 13 ms 4344 KB Output is correct
5 Correct 12 ms 3576 KB Output is correct
6 Correct 21 ms 5240 KB Output is correct
7 Correct 5 ms 2808 KB Output is correct
8 Correct 37 ms 6520 KB Output is correct
9 Correct 49 ms 8156 KB Output is correct
10 Correct 4 ms 2808 KB Output is correct
11 Correct 71 ms 9668 KB Output is correct
12 Correct 96 ms 11632 KB Output is correct
13 Correct 5 ms 2808 KB Output is correct
14 Correct 5 ms 2808 KB Output is correct
15 Correct 5 ms 2808 KB Output is correct
16 Correct 6 ms 2936 KB Output is correct
17 Correct 5 ms 2808 KB Output is correct
18 Correct 5 ms 2812 KB Output is correct
19 Correct 6 ms 2940 KB Output is correct
20 Correct 5 ms 2808 KB Output is correct
21 Incorrect 6 ms 2808 KB Output isn't correct
22 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 79 ms 13684 KB Output is correct
2 Correct 87 ms 13684 KB Output is correct
3 Correct 51 ms 9972 KB Output is correct
4 Correct 13 ms 4344 KB Output is correct
5 Correct 12 ms 3576 KB Output is correct
6 Correct 21 ms 5240 KB Output is correct
7 Correct 5 ms 2808 KB Output is correct
8 Correct 37 ms 6520 KB Output is correct
9 Correct 49 ms 8156 KB Output is correct
10 Correct 4 ms 2808 KB Output is correct
11 Correct 71 ms 9668 KB Output is correct
12 Correct 96 ms 11632 KB Output is correct
13 Correct 5 ms 2808 KB Output is correct
14 Correct 4 ms 2684 KB Output is correct
15 Correct 4 ms 2680 KB Output is correct
16 Correct 4 ms 2680 KB Output is correct
17 Correct 4 ms 2680 KB Output is correct
18 Correct 4 ms 2680 KB Output is correct
19 Correct 4 ms 2680 KB Output is correct
20 Correct 4 ms 2680 KB Output is correct
21 Correct 4 ms 2680 KB Output is correct
22 Correct 4 ms 2680 KB Output is correct
23 Correct 4 ms 2680 KB Output is correct
24 Correct 4 ms 2680 KB Output is correct
25 Correct 4 ms 2680 KB Output is correct
26 Correct 4 ms 2680 KB Output is correct
27 Correct 4 ms 2680 KB Output is correct
28 Correct 4 ms 2680 KB Output is correct
29 Correct 5 ms 2680 KB Output is correct
30 Correct 4 ms 2680 KB Output is correct
31 Correct 4 ms 2808 KB Output is correct
32 Correct 4 ms 2684 KB Output is correct
33 Correct 4 ms 2680 KB Output is correct
34 Correct 4 ms 2680 KB Output is correct
35 Correct 4 ms 2680 KB Output is correct
36 Correct 5 ms 2680 KB Output is correct
37 Correct 8 ms 2680 KB Output is correct
38 Correct 4 ms 2680 KB Output is correct
39 Correct 96 ms 14912 KB Output is correct
40 Correct 80 ms 15064 KB Output is correct
41 Correct 49 ms 10968 KB Output is correct
42 Correct 13 ms 4600 KB Output is correct
43 Correct 4 ms 2680 KB Output is correct
44 Correct 4 ms 2728 KB Output is correct
45 Correct 4 ms 2680 KB Output is correct
46 Correct 4 ms 2680 KB Output is correct
47 Correct 4 ms 2680 KB Output is correct
48 Correct 5 ms 2680 KB Output is correct
49 Correct 4 ms 2680 KB Output is correct
50 Correct 4 ms 2680 KB Output is correct
51 Correct 4 ms 2684 KB Output is correct
52 Correct 5 ms 2680 KB Output is correct
53 Correct 4 ms 2680 KB Output is correct
54 Correct 4 ms 2680 KB Output is correct
55 Correct 5 ms 2680 KB Output is correct
56 Correct 4 ms 2680 KB Output is correct
57 Correct 155 ms 10768 KB Output is correct
58 Correct 171 ms 10484 KB Output is correct
59 Correct 156 ms 10596 KB Output is correct
60 Correct 111 ms 10404 KB Output is correct
61 Correct 100 ms 10628 KB Output is correct
62 Correct 105 ms 10596 KB Output is correct
63 Correct 103 ms 10296 KB Output is correct
64 Correct 114 ms 10240 KB Output is correct
65 Correct 98 ms 10608 KB Output is correct
66 Correct 93 ms 10612 KB Output is correct
67 Correct 111 ms 10476 KB Output is correct
68 Correct 114 ms 10476 KB Output is correct
69 Correct 121 ms 10880 KB Output is correct
70 Correct 111 ms 10740 KB Output is correct
71 Correct 4 ms 2680 KB Output is correct
72 Correct 6 ms 2936 KB Output is correct
73 Correct 7 ms 2936 KB Output is correct
74 Correct 6 ms 2936 KB Output is correct
75 Correct 6 ms 2936 KB Output is correct
76 Correct 6 ms 2936 KB Output is correct
77 Correct 6 ms 2936 KB Output is correct
78 Correct 5 ms 2908 KB Output is correct
79 Correct 7 ms 2936 KB Output is correct
80 Correct 129 ms 10728 KB Output is correct
81 Correct 122 ms 10512 KB Output is correct
82 Correct 108 ms 10760 KB Output is correct
83 Correct 114 ms 10736 KB Output is correct
84 Correct 6 ms 2936 KB Output is correct
85 Correct 6 ms 2812 KB Output is correct
86 Correct 6 ms 2808 KB Output is correct
87 Correct 6 ms 2936 KB Output is correct
88 Correct 6 ms 2936 KB Output is correct
89 Correct 7 ms 2936 KB Output is correct
90 Correct 7 ms 2936 KB Output is correct
91 Correct 6 ms 2936 KB Output is correct
92 Correct 6 ms 2936 KB Output is correct
93 Correct 6 ms 2936 KB Output is correct
94 Correct 4 ms 2752 KB Output is correct
95 Correct 3 ms 2680 KB Output is correct
96 Correct 4 ms 2680 KB Output is correct
97 Correct 4 ms 2680 KB Output is correct
98 Correct 4 ms 2680 KB Output is correct
99 Correct 5 ms 2680 KB Output is correct
100 Correct 5 ms 2680 KB Output is correct
101 Correct 5 ms 2684 KB Output is correct
102 Correct 6 ms 2680 KB Output is correct
103 Correct 5 ms 2680 KB Output is correct
104 Correct 13 ms 3576 KB Output is correct
105 Correct 23 ms 5508 KB Output is correct
106 Correct 4 ms 2808 KB Output is correct
107 Correct 37 ms 7032 KB Output is correct
108 Correct 51 ms 8952 KB Output is correct
109 Correct 5 ms 2808 KB Output is correct
110 Correct 77 ms 10872 KB Output is correct
111 Correct 111 ms 12756 KB Output is correct
112 Correct 5 ms 2808 KB Output is correct
113 Correct 152 ms 16372 KB Output is correct
114 Correct 33 ms 6392 KB Output is correct
115 Incorrect 36 ms 6440 KB Output isn't correct
116 Halted 0 ms 0 KB -