Submission #293199

# Submission time Handle Problem Language Result Execution time Memory
293199 2020-09-07T18:23:44 Z alexandra_udristoiu Dreaming (IOI13_dreaming) C++14
47 / 100
109 ms 14840 KB
#include "dreaming.h"
#include<algorithm>
#include<vector>
#define DIM 100005
#define f first
#define s second
using namespace std;
static int viz[DIM], w[DIM], df[DIM], d[DIM][2], nr;
static vector< pair<int, int> > v[DIM];
static void dfs1(int nod){
    viz[nod] = 1;
    d[nod][0] = d[nod][1] = 0;
    for(int i = 0; i < v[nod].size(); i++){
        int vecin = v[nod][i].f;
        if(viz[vecin] == 0){
            dfs1(vecin);
            if(d[vecin][0] + v[nod][i].s > d[nod][0]){
                d[nod][1] = d[nod][0];
                d[nod][0] = d[vecin][0] + v[nod][i].s;
            }
            else{
                d[nod][1] = max(d[nod][1], d[vecin][0] + v[nod][i].s);
            }
        }
    }
}
static void dfs2(int nod){
    viz[nod] = 2;
    for(int i = 0; i < v[nod].size(); i++){
        int vecin = v[nod][i].f;
        if(viz[vecin] == 1){
            df[vecin] = df[nod] + v[nod][i].s;
            if(d[nod][0] != d[vecin][0] + v[nod][i].s){
                df[vecin] = max(df[vecin], d[nod][0] + v[nod][i].s);
            }
            else{
                df[vecin] = max(df[vecin], d[nod][1] + v[nod][i].s);
            }
            w[nr] = min(w[nr], max(d[vecin][0], df[vecin]) );
            dfs2(vecin);
        }
    }
}

int travelTime(int n, int m, int k, int a[], int b[], int t[]) {
    int i, sol;
    for(i = 0; i < m; i++){
        v[ a[i] ].push_back( make_pair(b[i], t[i]) );
        v[ b[i] ].push_back( make_pair(a[i], t[i]) );
    }
    for(i = 0; i < n; i++){
        if(viz[i] == 0){
            dfs1(i);
        }
    }
    for(i = 0; i < n; i++){
        if(viz[i] == 1){
            nr++;
            w[nr] = d[i][0];
            dfs2(i);
        }
    }
    sort(w + 1, w + nr + 1);
    if(nr == 2){
        sol = w[nr] + w[nr - 1] + k;
    }
    else{
        sol = max(w[nr] + w[nr - 1] + k, w[nr - 1] + w[nr - 2] + 2 * k);
    }
    for(i = 0; i < n; i++){
        sol = max(sol, d[i][0] + d[i][1]);
    }
    return sol;
}

Compilation message

dreaming.cpp: In function 'void dfs1(int)':
dreaming.cpp:13: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]
   13 |     for(int i = 0; i < v[nod].size(); i++){
      |                    ~~^~~~~~~~~~~~~~~
dreaming.cpp: In function 'void dfs2(int)':
dreaming.cpp:29: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]
   29 |     for(int i = 0; i < v[nod].size(); i++){
      |                    ~~^~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 58 ms 10360 KB Output is correct
2 Correct 57 ms 10232 KB Output is correct
3 Correct 45 ms 8572 KB Output is correct
4 Correct 9 ms 3840 KB Output is correct
5 Correct 8 ms 3328 KB Output is correct
6 Correct 15 ms 4352 KB Output is correct
7 Correct 2 ms 2688 KB Output is correct
8 Correct 34 ms 6564 KB Output is correct
9 Correct 43 ms 8184 KB Output is correct
10 Correct 2 ms 2688 KB Output is correct
11 Correct 65 ms 9460 KB Output is correct
12 Correct 84 ms 10572 KB Output is correct
13 Correct 3 ms 2816 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 58 ms 10360 KB Output is correct
2 Correct 57 ms 10232 KB Output is correct
3 Correct 45 ms 8572 KB Output is correct
4 Correct 9 ms 3840 KB Output is correct
5 Correct 8 ms 3328 KB Output is correct
6 Correct 15 ms 4352 KB Output is correct
7 Correct 2 ms 2688 KB Output is correct
8 Correct 34 ms 6564 KB Output is correct
9 Correct 43 ms 8184 KB Output is correct
10 Correct 2 ms 2688 KB Output is correct
11 Correct 65 ms 9460 KB Output is correct
12 Correct 84 ms 10572 KB Output is correct
13 Correct 3 ms 2816 KB Output is correct
14 Correct 2 ms 2688 KB Output is correct
15 Correct 2 ms 2688 KB Output is correct
16 Correct 2 ms 2688 KB Output is correct
17 Correct 2 ms 2688 KB Output is correct
18 Correct 2 ms 2688 KB Output is correct
19 Correct 2 ms 2688 KB Output is correct
20 Correct 2 ms 2688 KB Output is correct
21 Correct 2 ms 2688 KB Output is correct
22 Correct 2 ms 2688 KB Output is correct
23 Correct 2 ms 2688 KB Output is correct
24 Correct 2 ms 2688 KB Output is correct
25 Correct 2 ms 2688 KB Output is correct
26 Correct 2 ms 2688 KB Output is correct
27 Correct 2 ms 2688 KB Output is correct
28 Correct 2 ms 2688 KB Output is correct
29 Correct 2 ms 2688 KB Output is correct
30 Correct 2 ms 2688 KB Output is correct
31 Correct 2 ms 2688 KB Output is correct
32 Correct 2 ms 2688 KB Output is correct
33 Correct 2 ms 2688 KB Output is correct
34 Correct 2 ms 2688 KB Output is correct
35 Correct 2 ms 2688 KB Output is correct
36 Correct 2 ms 2688 KB Output is correct
37 Correct 2 ms 2688 KB Output is correct
38 Correct 2 ms 2688 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 58 ms 10360 KB Output is correct
2 Correct 57 ms 10232 KB Output is correct
3 Correct 45 ms 8572 KB Output is correct
4 Correct 9 ms 3840 KB Output is correct
5 Correct 8 ms 3328 KB Output is correct
6 Correct 15 ms 4352 KB Output is correct
7 Correct 2 ms 2688 KB Output is correct
8 Correct 34 ms 6564 KB Output is correct
9 Correct 43 ms 8184 KB Output is correct
10 Correct 2 ms 2688 KB Output is correct
11 Correct 65 ms 9460 KB Output is correct
12 Correct 84 ms 10572 KB Output is correct
13 Correct 3 ms 2816 KB Output is correct
14 Correct 2 ms 2688 KB Output is correct
15 Correct 2 ms 2688 KB Output is correct
16 Correct 2 ms 2688 KB Output is correct
17 Correct 2 ms 2688 KB Output is correct
18 Correct 2 ms 2688 KB Output is correct
19 Correct 2 ms 2688 KB Output is correct
20 Correct 2 ms 2688 KB Output is correct
21 Correct 2 ms 2688 KB Output is correct
22 Correct 2 ms 2688 KB Output is correct
23 Correct 2 ms 2688 KB Output is correct
24 Correct 2 ms 2688 KB Output is correct
25 Correct 2 ms 2688 KB Output is correct
26 Correct 2 ms 2688 KB Output is correct
27 Correct 2 ms 2688 KB Output is correct
28 Correct 2 ms 2688 KB Output is correct
29 Correct 2 ms 2688 KB Output is correct
30 Correct 2 ms 2688 KB Output is correct
31 Correct 2 ms 2688 KB Output is correct
32 Correct 2 ms 2688 KB Output is correct
33 Correct 2 ms 2688 KB Output is correct
34 Correct 2 ms 2688 KB Output is correct
35 Correct 2 ms 2688 KB Output is correct
36 Correct 2 ms 2688 KB Output is correct
37 Correct 2 ms 2688 KB Output is correct
38 Correct 2 ms 2688 KB Output is correct
39 Correct 58 ms 11640 KB Output is correct
40 Correct 61 ms 11384 KB Output is correct
41 Correct 42 ms 9592 KB Output is correct
42 Correct 9 ms 3968 KB Output is correct
43 Correct 2 ms 2688 KB Output is correct
44 Correct 2 ms 2688 KB Output is correct
45 Correct 2 ms 2688 KB Output is correct
46 Correct 2 ms 2688 KB Output is correct
47 Correct 2 ms 2688 KB Output is correct
48 Correct 2 ms 2688 KB Output is correct
49 Correct 2 ms 2688 KB Output is correct
50 Correct 2 ms 2688 KB Output is correct
51 Correct 2 ms 2688 KB Output is correct
52 Correct 2 ms 2688 KB Output is correct
53 Correct 2 ms 2688 KB Output is correct
54 Correct 2 ms 2688 KB Output is correct
55 Correct 2 ms 2688 KB Output is correct
56 Correct 2 ms 2720 KB Output is correct
57 Correct 90 ms 10744 KB Output is correct
58 Correct 88 ms 10744 KB Output is correct
59 Correct 87 ms 10616 KB Output is correct
60 Correct 88 ms 10616 KB Output is correct
61 Correct 90 ms 10740 KB Output is correct
62 Correct 94 ms 10744 KB Output is correct
63 Correct 82 ms 10360 KB Output is correct
64 Correct 83 ms 10360 KB Output is correct
65 Correct 87 ms 10744 KB Output is correct
66 Correct 91 ms 10744 KB Output is correct
67 Correct 99 ms 10692 KB Output is correct
68 Correct 82 ms 10616 KB Output is correct
69 Correct 96 ms 10912 KB Output is correct
70 Correct 109 ms 10872 KB Output is correct
71 Correct 2 ms 2688 KB Output is correct
72 Correct 3 ms 2944 KB Output is correct
73 Correct 3 ms 2944 KB Output is correct
74 Correct 4 ms 2944 KB Output is correct
75 Correct 4 ms 2944 KB Output is correct
76 Correct 3 ms 2944 KB Output is correct
77 Correct 4 ms 2944 KB Output is correct
78 Correct 4 ms 2944 KB Output is correct
79 Correct 4 ms 2944 KB Output is correct
80 Correct 82 ms 10616 KB Output is correct
81 Correct 95 ms 10616 KB Output is correct
82 Correct 85 ms 10748 KB Output is correct
83 Correct 87 ms 10744 KB Output is correct
84 Correct 3 ms 2816 KB Output is correct
85 Correct 3 ms 2816 KB Output is correct
86 Correct 3 ms 2816 KB Output is correct
87 Correct 3 ms 2816 KB Output is correct
88 Correct 4 ms 2816 KB Output is correct
89 Correct 3 ms 2816 KB Output is correct
90 Correct 4 ms 2816 KB Output is correct
91 Correct 3 ms 2944 KB Output is correct
92 Correct 3 ms 2944 KB Output is correct
93 Correct 3 ms 2816 KB Output is correct
94 Correct 2 ms 2688 KB Output is correct
95 Correct 2 ms 2688 KB Output is correct
96 Correct 2 ms 2688 KB Output is correct
97 Correct 3 ms 2688 KB Output is correct
98 Correct 2 ms 2688 KB Output is correct
99 Correct 2 ms 2688 KB Output is correct
100 Correct 2 ms 2688 KB Output is correct
101 Correct 2 ms 2688 KB Output is correct
102 Correct 2 ms 2688 KB Output is correct
103 Correct 2 ms 2688 KB Output is correct
104 Correct 8 ms 3584 KB Output is correct
105 Correct 15 ms 4608 KB Output is correct
106 Correct 2 ms 2688 KB Output is correct
107 Correct 28 ms 6528 KB Output is correct
108 Correct 35 ms 8056 KB Output is correct
109 Correct 2 ms 2688 KB Output is correct
110 Correct 58 ms 9464 KB Output is correct
111 Correct 69 ms 10364 KB Output is correct
112 Correct 2 ms 2816 KB Output is correct
113 Correct 102 ms 14840 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 36 ms 6648 KB Output is correct
2 Correct 29 ms 6776 KB Output is correct
3 Correct 29 ms 6728 KB Output is correct
4 Correct 28 ms 6648 KB Output is correct
5 Correct 28 ms 6656 KB Output is correct
6 Correct 30 ms 7032 KB Output is correct
7 Correct 29 ms 6904 KB Output is correct
8 Correct 29 ms 6648 KB Output is correct
9 Correct 29 ms 6648 KB Output is correct
10 Correct 32 ms 6904 KB Output is correct
11 Correct 2 ms 2688 KB Output is correct
12 Correct 6 ms 4608 KB Output is correct
13 Correct 6 ms 4608 KB Output is correct
14 Correct 5 ms 4640 KB Output is correct
15 Correct 5 ms 4608 KB Output is correct
16 Correct 5 ms 4480 KB Output is correct
17 Correct 5 ms 4352 KB Output is correct
18 Correct 6 ms 4608 KB Output is correct
19 Correct 5 ms 4480 KB Output is correct
20 Incorrect 2 ms 2688 KB Output isn't correct
21 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 58 ms 10360 KB Output is correct
2 Correct 57 ms 10232 KB Output is correct
3 Correct 45 ms 8572 KB Output is correct
4 Correct 9 ms 3840 KB Output is correct
5 Correct 8 ms 3328 KB Output is correct
6 Correct 15 ms 4352 KB Output is correct
7 Correct 2 ms 2688 KB Output is correct
8 Correct 34 ms 6564 KB Output is correct
9 Correct 43 ms 8184 KB Output is correct
10 Correct 2 ms 2688 KB Output is correct
11 Correct 65 ms 9460 KB Output is correct
12 Correct 84 ms 10572 KB Output is correct
13 Correct 3 ms 2816 KB Output is correct
14 Correct 2 ms 2816 KB Output is correct
15 Correct 3 ms 2816 KB Output is correct
16 Correct 3 ms 2944 KB Output is correct
17 Correct 2 ms 2688 KB Output is correct
18 Correct 3 ms 2816 KB Output is correct
19 Correct 4 ms 2944 KB Output is correct
20 Correct 2 ms 2688 KB Output is correct
21 Correct 3 ms 2944 KB Output is correct
22 Correct 3 ms 2944 KB Output is correct
23 Correct 2 ms 2688 KB Output is correct
24 Correct 2 ms 2688 KB Output is correct
25 Correct 2 ms 2688 KB Output is correct
26 Correct 2 ms 2688 KB Output is correct
27 Correct 2 ms 2688 KB Output is correct
28 Correct 2 ms 2688 KB Output is correct
29 Correct 2 ms 2688 KB Output is correct
30 Correct 2 ms 2688 KB Output is correct
31 Correct 2 ms 2688 KB Output is correct
32 Correct 2 ms 2688 KB Output is correct
33 Correct 2 ms 2688 KB Output is correct
34 Correct 2 ms 2688 KB Output is correct
35 Correct 2 ms 2688 KB Output is correct
36 Correct 2 ms 2688 KB Output is correct
37 Correct 2 ms 2688 KB Output is correct
38 Correct 2 ms 2688 KB Output is correct
39 Correct 2 ms 2688 KB Output is correct
40 Incorrect 2 ms 2688 KB Output isn't correct
41 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 58 ms 10360 KB Output is correct
2 Correct 57 ms 10232 KB Output is correct
3 Correct 45 ms 8572 KB Output is correct
4 Correct 9 ms 3840 KB Output is correct
5 Correct 8 ms 3328 KB Output is correct
6 Correct 15 ms 4352 KB Output is correct
7 Correct 2 ms 2688 KB Output is correct
8 Correct 34 ms 6564 KB Output is correct
9 Correct 43 ms 8184 KB Output is correct
10 Correct 2 ms 2688 KB Output is correct
11 Correct 65 ms 9460 KB Output is correct
12 Correct 84 ms 10572 KB Output is correct
13 Correct 3 ms 2816 KB Output is correct
14 Correct 2 ms 2688 KB Output is correct
15 Correct 2 ms 2688 KB Output is correct
16 Correct 2 ms 2688 KB Output is correct
17 Correct 2 ms 2688 KB Output is correct
18 Correct 2 ms 2688 KB Output is correct
19 Correct 2 ms 2688 KB Output is correct
20 Correct 2 ms 2688 KB Output is correct
21 Correct 2 ms 2688 KB Output is correct
22 Correct 2 ms 2688 KB Output is correct
23 Correct 2 ms 2688 KB Output is correct
24 Correct 2 ms 2688 KB Output is correct
25 Correct 2 ms 2688 KB Output is correct
26 Correct 2 ms 2688 KB Output is correct
27 Correct 2 ms 2688 KB Output is correct
28 Correct 2 ms 2688 KB Output is correct
29 Correct 2 ms 2688 KB Output is correct
30 Correct 2 ms 2688 KB Output is correct
31 Correct 2 ms 2688 KB Output is correct
32 Correct 2 ms 2688 KB Output is correct
33 Correct 2 ms 2688 KB Output is correct
34 Correct 2 ms 2688 KB Output is correct
35 Correct 2 ms 2688 KB Output is correct
36 Correct 2 ms 2688 KB Output is correct
37 Correct 2 ms 2688 KB Output is correct
38 Correct 2 ms 2688 KB Output is correct
39 Correct 58 ms 11640 KB Output is correct
40 Correct 61 ms 11384 KB Output is correct
41 Correct 42 ms 9592 KB Output is correct
42 Correct 9 ms 3968 KB Output is correct
43 Correct 2 ms 2688 KB Output is correct
44 Correct 2 ms 2688 KB Output is correct
45 Correct 2 ms 2688 KB Output is correct
46 Correct 2 ms 2688 KB Output is correct
47 Correct 2 ms 2688 KB Output is correct
48 Correct 2 ms 2688 KB Output is correct
49 Correct 2 ms 2688 KB Output is correct
50 Correct 2 ms 2688 KB Output is correct
51 Correct 2 ms 2688 KB Output is correct
52 Correct 2 ms 2688 KB Output is correct
53 Correct 2 ms 2688 KB Output is correct
54 Correct 2 ms 2688 KB Output is correct
55 Correct 2 ms 2688 KB Output is correct
56 Correct 2 ms 2720 KB Output is correct
57 Correct 90 ms 10744 KB Output is correct
58 Correct 88 ms 10744 KB Output is correct
59 Correct 87 ms 10616 KB Output is correct
60 Correct 88 ms 10616 KB Output is correct
61 Correct 90 ms 10740 KB Output is correct
62 Correct 94 ms 10744 KB Output is correct
63 Correct 82 ms 10360 KB Output is correct
64 Correct 83 ms 10360 KB Output is correct
65 Correct 87 ms 10744 KB Output is correct
66 Correct 91 ms 10744 KB Output is correct
67 Correct 99 ms 10692 KB Output is correct
68 Correct 82 ms 10616 KB Output is correct
69 Correct 96 ms 10912 KB Output is correct
70 Correct 109 ms 10872 KB Output is correct
71 Correct 2 ms 2688 KB Output is correct
72 Correct 3 ms 2944 KB Output is correct
73 Correct 3 ms 2944 KB Output is correct
74 Correct 4 ms 2944 KB Output is correct
75 Correct 4 ms 2944 KB Output is correct
76 Correct 3 ms 2944 KB Output is correct
77 Correct 4 ms 2944 KB Output is correct
78 Correct 4 ms 2944 KB Output is correct
79 Correct 4 ms 2944 KB Output is correct
80 Correct 82 ms 10616 KB Output is correct
81 Correct 95 ms 10616 KB Output is correct
82 Correct 85 ms 10748 KB Output is correct
83 Correct 87 ms 10744 KB Output is correct
84 Correct 3 ms 2816 KB Output is correct
85 Correct 3 ms 2816 KB Output is correct
86 Correct 3 ms 2816 KB Output is correct
87 Correct 3 ms 2816 KB Output is correct
88 Correct 4 ms 2816 KB Output is correct
89 Correct 3 ms 2816 KB Output is correct
90 Correct 4 ms 2816 KB Output is correct
91 Correct 3 ms 2944 KB Output is correct
92 Correct 3 ms 2944 KB Output is correct
93 Correct 3 ms 2816 KB Output is correct
94 Correct 2 ms 2688 KB Output is correct
95 Correct 2 ms 2688 KB Output is correct
96 Correct 2 ms 2688 KB Output is correct
97 Correct 3 ms 2688 KB Output is correct
98 Correct 2 ms 2688 KB Output is correct
99 Correct 2 ms 2688 KB Output is correct
100 Correct 2 ms 2688 KB Output is correct
101 Correct 2 ms 2688 KB Output is correct
102 Correct 2 ms 2688 KB Output is correct
103 Correct 2 ms 2688 KB Output is correct
104 Correct 8 ms 3584 KB Output is correct
105 Correct 15 ms 4608 KB Output is correct
106 Correct 2 ms 2688 KB Output is correct
107 Correct 28 ms 6528 KB Output is correct
108 Correct 35 ms 8056 KB Output is correct
109 Correct 2 ms 2688 KB Output is correct
110 Correct 58 ms 9464 KB Output is correct
111 Correct 69 ms 10364 KB Output is correct
112 Correct 2 ms 2816 KB Output is correct
113 Correct 102 ms 14840 KB Output is correct
114 Correct 36 ms 6648 KB Output is correct
115 Correct 29 ms 6776 KB Output is correct
116 Correct 29 ms 6728 KB Output is correct
117 Correct 28 ms 6648 KB Output is correct
118 Correct 28 ms 6656 KB Output is correct
119 Correct 30 ms 7032 KB Output is correct
120 Correct 29 ms 6904 KB Output is correct
121 Correct 29 ms 6648 KB Output is correct
122 Correct 29 ms 6648 KB Output is correct
123 Correct 32 ms 6904 KB Output is correct
124 Correct 2 ms 2688 KB Output is correct
125 Correct 6 ms 4608 KB Output is correct
126 Correct 6 ms 4608 KB Output is correct
127 Correct 5 ms 4640 KB Output is correct
128 Correct 5 ms 4608 KB Output is correct
129 Correct 5 ms 4480 KB Output is correct
130 Correct 5 ms 4352 KB Output is correct
131 Correct 6 ms 4608 KB Output is correct
132 Correct 5 ms 4480 KB Output is correct
133 Incorrect 2 ms 2688 KB Output isn't correct
134 Halted 0 ms 0 KB -