Submission #134812

# Submission time Handle Problem Language Result Execution time Memory
134812 2019-07-23T09:39:23 Z mirbek01 Dreaming (IOI13_dreaming) C++11
47 / 100
149 ms 24060 KB
#include "dreaming.h"
//#include "grader.cpp"
#include <bits/stdc++.h>

using namespace std;

const int N = 1e5 + 3;

int u[N], dw[N], up[N], ans, mx;
vector < pair <int, int> >  g[N];

void dfs(int v, int pr){
	u[v] = 1;
	int mx1 = 0, mx2 = 0;
	for(int i = 0; i < (int)g[v].size(); i ++){
		int to = g[v][i].first, len = g[v][i].second;
		if(to == pr)
			continue;
		dfs(to, v);
		dw[v] = max(dw[v], dw[to] + len); 
		if(mx1 < dw[to] + len)
			mx2 = mx1, mx1 = dw[to] + len;
		else 
			mx2 = max(mx2, dw[to] + len);
	} 
	ans = max(ans, mx1 + mx2);
}
	
void dfs1(int v, int pr){
	mx = min(mx, max(up[v], dw[v]));
	vector < pair <int, int> > vec;
	for(int i = 0; i < (int)g[v].size(); i ++){
		int to = g[v][i].first, len = g[v][i].second;
		if(to == pr) continue;
		vec.push_back( {dw[to] + len, to} );
	}
	sort(vec.rbegin(), vec.rend());
	for(int i = 0; i < (int)g[v].size(); i ++){
		int to = g[v][i].first, len = g[v][i].second;
		if(to == pr)
			continue;
			up[to] = max(up[to], up[v] + len);
		if(to == vec[0].second){
			if((int)vec.size() > 1)
				up[to] = max(up[to], vec[1].first + len);
		} else {
			up[to] = max(up[to], vec[0].first + len);
		}
		dfs1(to, v);
	}
}

int travelTime(int N, int M, int L, int A[], int B[], int T[]) {
	for(int i = 0; i < M; i ++){
		int u = A[i], v = B[i], w = T[i];
		g[u].push_back( {v, w} );
		g[v].push_back( {u, w} );
	}

	vector <int> vec;
	
	for(int i = 0; i < N; i ++){
		if(!u[i]){
			mx = 2e9;
			dfs(i, -1);
			dfs1(i, -1);
			vec.push_back(mx);
		}
	}
	
	sort(vec.rbegin(), vec.rend());
	
	if((int)vec.size() > 1)
		ans = max(ans, vec[0] + vec[1] + L);
		
	return ans;
}
/**
12 8 2
0 8 4
8 2 2
2 7 4
5 11 3
5 1 7
1 3 1
1 9 5
10 6 3
**/

Compilation message

dreaming.cpp: In function 'void dfs1(int, int)':
dreaming.cpp:40:3: warning: this 'if' clause does not guard... [-Wmisleading-indentation]
   if(to == pr)
   ^~
dreaming.cpp:42:4: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'if'
    up[to] = max(up[to], up[v] + len);
    ^~
# Verdict Execution time Memory Grader output
1 Correct 78 ms 15736 KB Output is correct
2 Correct 78 ms 15224 KB Output is correct
3 Correct 69 ms 14232 KB Output is correct
4 Correct 17 ms 4728 KB Output is correct
5 Correct 12 ms 3832 KB Output is correct
6 Correct 22 ms 5752 KB Output is correct
7 Correct 4 ms 2808 KB Output is correct
8 Correct 39 ms 8412 KB Output is correct
9 Correct 51 ms 12012 KB Output is correct
10 Correct 5 ms 2808 KB Output is correct
11 Correct 74 ms 12252 KB Output is correct
12 Correct 85 ms 14072 KB Output is correct
13 Correct 4 ms 2808 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 78 ms 15736 KB Output is correct
2 Correct 78 ms 15224 KB Output is correct
3 Correct 69 ms 14232 KB Output is correct
4 Correct 17 ms 4728 KB Output is correct
5 Correct 12 ms 3832 KB Output is correct
6 Correct 22 ms 5752 KB Output is correct
7 Correct 4 ms 2808 KB Output is correct
8 Correct 39 ms 8412 KB Output is correct
9 Correct 51 ms 12012 KB Output is correct
10 Correct 5 ms 2808 KB Output is correct
11 Correct 74 ms 12252 KB Output is correct
12 Correct 85 ms 14072 KB Output is correct
13 Correct 4 ms 2808 KB Output is correct
14 Correct 4 ms 2680 KB Output is correct
15 Correct 4 ms 2680 KB Output is correct
16 Correct 5 ms 2680 KB Output is correct
17 Correct 5 ms 2756 KB Output is correct
18 Correct 5 ms 2680 KB Output is correct
19 Correct 4 ms 2684 KB Output is correct
20 Correct 4 ms 2680 KB Output is correct
21 Correct 5 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 2684 KB Output is correct
27 Correct 4 ms 2680 KB Output is correct
28 Correct 4 ms 2680 KB Output is correct
29 Correct 4 ms 2680 KB Output is correct
30 Correct 4 ms 2680 KB Output is correct
31 Correct 4 ms 2680 KB Output is correct
32 Correct 4 ms 2680 KB Output is correct
33 Correct 4 ms 2684 KB Output is correct
34 Correct 5 ms 2680 KB Output is correct
35 Correct 5 ms 2680 KB Output is correct
36 Correct 5 ms 2680 KB Output is correct
37 Correct 4 ms 2724 KB Output is correct
38 Correct 2 ms 2680 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 78 ms 15736 KB Output is correct
2 Correct 78 ms 15224 KB Output is correct
3 Correct 69 ms 14232 KB Output is correct
4 Correct 17 ms 4728 KB Output is correct
5 Correct 12 ms 3832 KB Output is correct
6 Correct 22 ms 5752 KB Output is correct
7 Correct 4 ms 2808 KB Output is correct
8 Correct 39 ms 8412 KB Output is correct
9 Correct 51 ms 12012 KB Output is correct
10 Correct 5 ms 2808 KB Output is correct
11 Correct 74 ms 12252 KB Output is correct
12 Correct 85 ms 14072 KB Output is correct
13 Correct 4 ms 2808 KB Output is correct
14 Correct 4 ms 2680 KB Output is correct
15 Correct 4 ms 2680 KB Output is correct
16 Correct 5 ms 2680 KB Output is correct
17 Correct 5 ms 2756 KB Output is correct
18 Correct 5 ms 2680 KB Output is correct
19 Correct 4 ms 2684 KB Output is correct
20 Correct 4 ms 2680 KB Output is correct
21 Correct 5 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 2684 KB Output is correct
27 Correct 4 ms 2680 KB Output is correct
28 Correct 4 ms 2680 KB Output is correct
29 Correct 4 ms 2680 KB Output is correct
30 Correct 4 ms 2680 KB Output is correct
31 Correct 4 ms 2680 KB Output is correct
32 Correct 4 ms 2680 KB Output is correct
33 Correct 4 ms 2684 KB Output is correct
34 Correct 5 ms 2680 KB Output is correct
35 Correct 5 ms 2680 KB Output is correct
36 Correct 5 ms 2680 KB Output is correct
37 Correct 4 ms 2724 KB Output is correct
38 Correct 2 ms 2680 KB Output is correct
39 Correct 85 ms 16252 KB Output is correct
40 Correct 82 ms 15480 KB Output is correct
41 Correct 59 ms 14456 KB Output is correct
42 Correct 14 ms 4728 KB Output is correct
43 Correct 4 ms 2680 KB Output is correct
44 Correct 4 ms 2680 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 4 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 2680 KB Output is correct
52 Correct 4 ms 2680 KB Output is correct
53 Correct 4 ms 2684 KB Output is correct
54 Correct 4 ms 2680 KB Output is correct
55 Correct 4 ms 2680 KB Output is correct
56 Correct 4 ms 2680 KB Output is correct
57 Correct 95 ms 9592 KB Output is correct
58 Correct 100 ms 9464 KB Output is correct
59 Correct 121 ms 9564 KB Output is correct
60 Correct 99 ms 9548 KB Output is correct
61 Correct 98 ms 9336 KB Output is correct
62 Correct 127 ms 9336 KB Output is correct
63 Correct 90 ms 9188 KB Output is correct
64 Correct 103 ms 9220 KB Output is correct
65 Correct 94 ms 9336 KB Output is correct
66 Correct 94 ms 9248 KB Output is correct
67 Correct 104 ms 9720 KB Output is correct
68 Correct 94 ms 9464 KB Output is correct
69 Correct 111 ms 9612 KB Output is correct
70 Correct 149 ms 9464 KB Output is correct
71 Correct 5 ms 2680 KB Output is correct
72 Correct 7 ms 2936 KB Output is correct
73 Correct 6 ms 2936 KB Output is correct
74 Correct 6 ms 2936 KB Output is correct
75 Correct 7 ms 2936 KB Output is correct
76 Correct 7 ms 2936 KB Output is correct
77 Correct 7 ms 2936 KB Output is correct
78 Correct 6 ms 2936 KB Output is correct
79 Correct 7 ms 2936 KB Output is correct
80 Correct 134 ms 9572 KB Output is correct
81 Correct 92 ms 9636 KB Output is correct
82 Correct 92 ms 9400 KB Output is correct
83 Correct 97 ms 9464 KB Output is correct
84 Correct 5 ms 2936 KB Output is correct
85 Correct 5 ms 2844 KB Output is correct
86 Correct 6 ms 2936 KB Output is correct
87 Correct 7 ms 2936 KB Output is correct
88 Correct 6 ms 2936 KB Output is correct
89 Correct 6 ms 2936 KB Output is correct
90 Correct 6 ms 2936 KB Output is correct
91 Correct 6 ms 2936 KB Output is correct
92 Correct 7 ms 2936 KB Output is correct
93 Correct 7 ms 2936 KB Output is correct
94 Correct 4 ms 2808 KB Output is correct
95 Correct 4 ms 2680 KB Output is correct
96 Correct 4 ms 2680 KB Output is correct
97 Correct 4 ms 2732 KB Output is correct
98 Correct 4 ms 2680 KB Output is correct
99 Correct 4 ms 2680 KB Output is correct
100 Correct 4 ms 2680 KB Output is correct
101 Correct 4 ms 2680 KB Output is correct
102 Correct 5 ms 2680 KB Output is correct
103 Correct 4 ms 2680 KB Output is correct
104 Correct 12 ms 3832 KB Output is correct
105 Correct 24 ms 5880 KB Output is correct
106 Correct 4 ms 2680 KB Output is correct
107 Correct 38 ms 8472 KB Output is correct
108 Correct 51 ms 12024 KB Output is correct
109 Correct 4 ms 2808 KB Output is correct
110 Correct 78 ms 12280 KB Output is correct
111 Correct 92 ms 14072 KB Output is correct
112 Correct 5 ms 2896 KB Output is correct
113 Correct 121 ms 24060 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 35 ms 6648 KB Output is correct
2 Incorrect 35 ms 6904 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 78 ms 15736 KB Output is correct
2 Correct 78 ms 15224 KB Output is correct
3 Correct 69 ms 14232 KB Output is correct
4 Correct 17 ms 4728 KB Output is correct
5 Correct 12 ms 3832 KB Output is correct
6 Correct 22 ms 5752 KB Output is correct
7 Correct 4 ms 2808 KB Output is correct
8 Correct 39 ms 8412 KB Output is correct
9 Correct 51 ms 12012 KB Output is correct
10 Correct 5 ms 2808 KB Output is correct
11 Correct 74 ms 12252 KB Output is correct
12 Correct 85 ms 14072 KB Output is correct
13 Correct 4 ms 2808 KB Output is correct
14 Correct 4 ms 2808 KB Output is correct
15 Correct 5 ms 2808 KB Output is correct
16 Correct 7 ms 2936 KB Output is correct
17 Correct 5 ms 2680 KB Output is correct
18 Correct 6 ms 2808 KB Output is correct
19 Correct 6 ms 2940 KB Output is correct
20 Incorrect 5 ms 2724 KB Output isn't correct
21 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 78 ms 15736 KB Output is correct
2 Correct 78 ms 15224 KB Output is correct
3 Correct 69 ms 14232 KB Output is correct
4 Correct 17 ms 4728 KB Output is correct
5 Correct 12 ms 3832 KB Output is correct
6 Correct 22 ms 5752 KB Output is correct
7 Correct 4 ms 2808 KB Output is correct
8 Correct 39 ms 8412 KB Output is correct
9 Correct 51 ms 12012 KB Output is correct
10 Correct 5 ms 2808 KB Output is correct
11 Correct 74 ms 12252 KB Output is correct
12 Correct 85 ms 14072 KB Output is correct
13 Correct 4 ms 2808 KB Output is correct
14 Correct 4 ms 2680 KB Output is correct
15 Correct 4 ms 2680 KB Output is correct
16 Correct 5 ms 2680 KB Output is correct
17 Correct 5 ms 2756 KB Output is correct
18 Correct 5 ms 2680 KB Output is correct
19 Correct 4 ms 2684 KB Output is correct
20 Correct 4 ms 2680 KB Output is correct
21 Correct 5 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 2684 KB Output is correct
27 Correct 4 ms 2680 KB Output is correct
28 Correct 4 ms 2680 KB Output is correct
29 Correct 4 ms 2680 KB Output is correct
30 Correct 4 ms 2680 KB Output is correct
31 Correct 4 ms 2680 KB Output is correct
32 Correct 4 ms 2680 KB Output is correct
33 Correct 4 ms 2684 KB Output is correct
34 Correct 5 ms 2680 KB Output is correct
35 Correct 5 ms 2680 KB Output is correct
36 Correct 5 ms 2680 KB Output is correct
37 Correct 4 ms 2724 KB Output is correct
38 Correct 2 ms 2680 KB Output is correct
39 Correct 85 ms 16252 KB Output is correct
40 Correct 82 ms 15480 KB Output is correct
41 Correct 59 ms 14456 KB Output is correct
42 Correct 14 ms 4728 KB Output is correct
43 Correct 4 ms 2680 KB Output is correct
44 Correct 4 ms 2680 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 4 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 2680 KB Output is correct
52 Correct 4 ms 2680 KB Output is correct
53 Correct 4 ms 2684 KB Output is correct
54 Correct 4 ms 2680 KB Output is correct
55 Correct 4 ms 2680 KB Output is correct
56 Correct 4 ms 2680 KB Output is correct
57 Correct 95 ms 9592 KB Output is correct
58 Correct 100 ms 9464 KB Output is correct
59 Correct 121 ms 9564 KB Output is correct
60 Correct 99 ms 9548 KB Output is correct
61 Correct 98 ms 9336 KB Output is correct
62 Correct 127 ms 9336 KB Output is correct
63 Correct 90 ms 9188 KB Output is correct
64 Correct 103 ms 9220 KB Output is correct
65 Correct 94 ms 9336 KB Output is correct
66 Correct 94 ms 9248 KB Output is correct
67 Correct 104 ms 9720 KB Output is correct
68 Correct 94 ms 9464 KB Output is correct
69 Correct 111 ms 9612 KB Output is correct
70 Correct 149 ms 9464 KB Output is correct
71 Correct 5 ms 2680 KB Output is correct
72 Correct 7 ms 2936 KB Output is correct
73 Correct 6 ms 2936 KB Output is correct
74 Correct 6 ms 2936 KB Output is correct
75 Correct 7 ms 2936 KB Output is correct
76 Correct 7 ms 2936 KB Output is correct
77 Correct 7 ms 2936 KB Output is correct
78 Correct 6 ms 2936 KB Output is correct
79 Correct 7 ms 2936 KB Output is correct
80 Correct 134 ms 9572 KB Output is correct
81 Correct 92 ms 9636 KB Output is correct
82 Correct 92 ms 9400 KB Output is correct
83 Correct 97 ms 9464 KB Output is correct
84 Correct 5 ms 2936 KB Output is correct
85 Correct 5 ms 2844 KB Output is correct
86 Correct 6 ms 2936 KB Output is correct
87 Correct 7 ms 2936 KB Output is correct
88 Correct 6 ms 2936 KB Output is correct
89 Correct 6 ms 2936 KB Output is correct
90 Correct 6 ms 2936 KB Output is correct
91 Correct 6 ms 2936 KB Output is correct
92 Correct 7 ms 2936 KB Output is correct
93 Correct 7 ms 2936 KB Output is correct
94 Correct 4 ms 2808 KB Output is correct
95 Correct 4 ms 2680 KB Output is correct
96 Correct 4 ms 2680 KB Output is correct
97 Correct 4 ms 2732 KB Output is correct
98 Correct 4 ms 2680 KB Output is correct
99 Correct 4 ms 2680 KB Output is correct
100 Correct 4 ms 2680 KB Output is correct
101 Correct 4 ms 2680 KB Output is correct
102 Correct 5 ms 2680 KB Output is correct
103 Correct 4 ms 2680 KB Output is correct
104 Correct 12 ms 3832 KB Output is correct
105 Correct 24 ms 5880 KB Output is correct
106 Correct 4 ms 2680 KB Output is correct
107 Correct 38 ms 8472 KB Output is correct
108 Correct 51 ms 12024 KB Output is correct
109 Correct 4 ms 2808 KB Output is correct
110 Correct 78 ms 12280 KB Output is correct
111 Correct 92 ms 14072 KB Output is correct
112 Correct 5 ms 2896 KB Output is correct
113 Correct 121 ms 24060 KB Output is correct
114 Correct 35 ms 6648 KB Output is correct
115 Incorrect 35 ms 6904 KB Output isn't correct
116 Halted 0 ms 0 KB -