Submission #210677

# Submission time Handle Problem Language Result Execution time Memory
210677 2020-03-18T01:46:48 Z peuch Dreaming (IOI13_dreaming) C++17
47 / 100
177 ms 20344 KB
#include<bits/stdc++.h>
#include "dreaming.h"
using namespace std;

const int MAXN = 1e5 + 10; 

int marc[MAXN], dist[MAXN], longDist[2][MAXN];
int aux;

vector<int> ar[MAXN];
vector<int> wg[MAXN];
vector<int> group;

int dfs1(int cur);
int dfs2(int cur);
int dfs3(int cur);

int travelTime(int N, int M, int L, int A[], int B[], int T[]) {
	for(int i = 0; i < M; i++){
		ar[A[i]].push_back(B[i]);
		ar[B[i]].push_back(A[i]);
		wg[A[i]].push_back(T[i]);
		wg[B[i]].push_back(T[i]);
	}
	int ret = 0;
	for(int i = 0; i < N; i++){
		if(marc[i] == 3) continue;
		dist[i] = 0;
		aux = 0;
		int side1 = dfs1(i);
		longDist[0][side1] = 0;
		int side2 = dfs2(side1);
		ret = max(ret, longDist[0][side2]);
		// printf("group: %d ends = %d and %d with %d nodes\n", group.size(), side1, side2, aux);
		longDist[1][side2] = 0;
		group.push_back(dfs3(side2));
	}	
	// printf("%d\n", group.size());
	// for(int i = 0; i < group.size(); i++)
	// 	printf("%d ", group[i]);
	// printf("\n");
	if(group.size() == 1){
		for(int i = 0; i < N; i++)
			ret = max(ret, longDist[0][i]);
		return ret;
	}
	for(int i = 1; i < group.size(); i++){
		ret = max(ret, group[i] + group[i - 1] + L);
		group[i] = min(max(group[i], group[i - 1] + L), max(group[i - 1], group[i] + L));
	}
    return ret;
}

int dfs1(int cur){
	marc[cur] = 1;
	aux++;
	int ret = cur;
	int auxRet = dist[cur];
	for(int i = 0; i < ar[cur].size(); i++){
		int viz = ar[cur][i];
		int len = wg[cur][i];
		if(marc[viz] == 1) continue;
		dist[viz] = dist[cur] + len;
		int dfsVal = dfs1(viz);
		if(dist[dfsVal] > auxRet) ret = dfsVal, auxRet = dist[dfsVal];
 	} 
 	return ret;
}

int dfs2(int cur){
	marc[cur] = 2;
	int ret = cur;
	int auxRet = longDist[0][cur];
	for(int i = 0; i < ar[cur].size(); i++){
		int viz = ar[cur][i];
		int len = wg[cur][i];
		if(marc[viz] == 2) continue;
		longDist[0][viz] = longDist[0][cur] + len;
		int dfsVal = dfs2(viz);
		if(longDist[0][dfsVal] > auxRet) ret = dfsVal, auxRet = longDist[0][dfsVal];
 	} 
 	return ret;
}

int dfs3(int cur){
	marc[cur] = 3;
	int ret = max(longDist[0][cur], longDist[1][cur]);
	for(int i = 0; i < ar[cur].size(); i++){
		int viz = ar[cur][i];
		int len = wg[cur][i];
		if(marc[viz] == 3) continue;
		longDist[1][viz] = longDist[1][cur] + len;
		ret = min(ret, dfs3(viz));
 	} 
 	// printf("%d max(%d %d) -> %d\n", cur, longDist[0][cur], longDist[1][cur], ret);
 	return ret;
}

Compilation message

dreaming.cpp: In function 'int travelTime(int, int, int, int*, int*, int*)':
dreaming.cpp:47:19: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for(int i = 1; i < group.size(); i++){
                 ~~^~~~~~~~~~~~~~
dreaming.cpp: In function 'int dfs1(int)':
dreaming.cpp:59:19: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for(int i = 0; i < ar[cur].size(); i++){
                 ~~^~~~~~~~~~~~~~~~
dreaming.cpp: In function 'int dfs2(int)':
dreaming.cpp:74:19: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for(int i = 0; i < ar[cur].size(); i++){
                 ~~^~~~~~~~~~~~~~~~
dreaming.cpp: In function 'int dfs3(int)':
dreaming.cpp:88:19: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for(int i = 0; i < ar[cur].size(); i++){
                 ~~^~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 91 ms 19192 KB Output is correct
2 Correct 94 ms 19064 KB Output is correct
3 Correct 58 ms 14328 KB Output is correct
4 Correct 17 ms 7160 KB Output is correct
5 Correct 15 ms 6392 KB Output is correct
6 Correct 24 ms 8184 KB Output is correct
7 Correct 8 ms 5112 KB Output is correct
8 Correct 45 ms 10232 KB Output is correct
9 Correct 61 ms 12152 KB Output is correct
10 Correct 8 ms 5112 KB Output is correct
11 Correct 101 ms 14456 KB Output is correct
12 Correct 123 ms 16632 KB Output is correct
13 Correct 8 ms 5112 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 91 ms 19192 KB Output is correct
2 Correct 94 ms 19064 KB Output is correct
3 Correct 58 ms 14328 KB Output is correct
4 Correct 17 ms 7160 KB Output is correct
5 Correct 15 ms 6392 KB Output is correct
6 Correct 24 ms 8184 KB Output is correct
7 Correct 8 ms 5112 KB Output is correct
8 Correct 45 ms 10232 KB Output is correct
9 Correct 61 ms 12152 KB Output is correct
10 Correct 8 ms 5112 KB Output is correct
11 Correct 101 ms 14456 KB Output is correct
12 Correct 123 ms 16632 KB Output is correct
13 Correct 8 ms 5112 KB Output is correct
14 Correct 8 ms 4980 KB Output is correct
15 Correct 7 ms 4984 KB Output is correct
16 Correct 8 ms 4984 KB Output is correct
17 Correct 7 ms 4984 KB Output is correct
18 Correct 8 ms 4988 KB Output is correct
19 Correct 7 ms 4984 KB Output is correct
20 Correct 7 ms 4984 KB Output is correct
21 Correct 7 ms 4984 KB Output is correct
22 Correct 9 ms 5112 KB Output is correct
23 Correct 7 ms 4984 KB Output is correct
24 Correct 8 ms 5112 KB Output is correct
25 Correct 7 ms 4984 KB Output is correct
26 Correct 8 ms 5112 KB Output is correct
27 Correct 7 ms 4984 KB Output is correct
28 Correct 7 ms 4984 KB Output is correct
29 Correct 7 ms 4984 KB Output is correct
30 Correct 8 ms 4988 KB Output is correct
31 Correct 8 ms 4984 KB Output is correct
32 Correct 7 ms 4984 KB Output is correct
33 Correct 7 ms 5164 KB Output is correct
34 Correct 7 ms 4984 KB Output is correct
35 Correct 8 ms 4984 KB Output is correct
36 Correct 7 ms 4984 KB Output is correct
37 Correct 8 ms 4984 KB Output is correct
38 Correct 8 ms 4984 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 91 ms 19192 KB Output is correct
2 Correct 94 ms 19064 KB Output is correct
3 Correct 58 ms 14328 KB Output is correct
4 Correct 17 ms 7160 KB Output is correct
5 Correct 15 ms 6392 KB Output is correct
6 Correct 24 ms 8184 KB Output is correct
7 Correct 8 ms 5112 KB Output is correct
8 Correct 45 ms 10232 KB Output is correct
9 Correct 61 ms 12152 KB Output is correct
10 Correct 8 ms 5112 KB Output is correct
11 Correct 101 ms 14456 KB Output is correct
12 Correct 123 ms 16632 KB Output is correct
13 Correct 8 ms 5112 KB Output is correct
14 Correct 8 ms 4980 KB Output is correct
15 Correct 7 ms 4984 KB Output is correct
16 Correct 8 ms 4984 KB Output is correct
17 Correct 7 ms 4984 KB Output is correct
18 Correct 8 ms 4988 KB Output is correct
19 Correct 7 ms 4984 KB Output is correct
20 Correct 7 ms 4984 KB Output is correct
21 Correct 7 ms 4984 KB Output is correct
22 Correct 9 ms 5112 KB Output is correct
23 Correct 7 ms 4984 KB Output is correct
24 Correct 8 ms 5112 KB Output is correct
25 Correct 7 ms 4984 KB Output is correct
26 Correct 8 ms 5112 KB Output is correct
27 Correct 7 ms 4984 KB Output is correct
28 Correct 7 ms 4984 KB Output is correct
29 Correct 7 ms 4984 KB Output is correct
30 Correct 8 ms 4988 KB Output is correct
31 Correct 8 ms 4984 KB Output is correct
32 Correct 7 ms 4984 KB Output is correct
33 Correct 7 ms 5164 KB Output is correct
34 Correct 7 ms 4984 KB Output is correct
35 Correct 8 ms 4984 KB Output is correct
36 Correct 7 ms 4984 KB Output is correct
37 Correct 8 ms 4984 KB Output is correct
38 Correct 8 ms 4984 KB Output is correct
39 Correct 102 ms 19064 KB Output is correct
40 Correct 102 ms 19064 KB Output is correct
41 Correct 57 ms 14328 KB Output is correct
42 Correct 18 ms 7160 KB Output is correct
43 Correct 8 ms 4984 KB Output is correct
44 Correct 8 ms 4984 KB Output is correct
45 Correct 9 ms 5112 KB Output is correct
46 Correct 8 ms 4984 KB Output is correct
47 Correct 8 ms 4984 KB Output is correct
48 Correct 7 ms 4984 KB Output is correct
49 Correct 8 ms 4984 KB Output is correct
50 Correct 7 ms 5112 KB Output is correct
51 Correct 8 ms 5112 KB Output is correct
52 Correct 7 ms 4984 KB Output is correct
53 Correct 8 ms 4984 KB Output is correct
54 Correct 7 ms 4984 KB Output is correct
55 Correct 8 ms 4984 KB Output is correct
56 Correct 7 ms 4984 KB Output is correct
57 Correct 155 ms 14076 KB Output is correct
58 Correct 154 ms 14072 KB Output is correct
59 Correct 153 ms 14332 KB Output is correct
60 Correct 157 ms 14328 KB Output is correct
61 Correct 147 ms 14456 KB Output is correct
62 Correct 148 ms 14456 KB Output is correct
63 Correct 137 ms 14264 KB Output is correct
64 Correct 134 ms 14328 KB Output is correct
65 Correct 141 ms 14348 KB Output is correct
66 Correct 139 ms 14328 KB Output is correct
67 Correct 145 ms 14200 KB Output is correct
68 Correct 151 ms 14204 KB Output is correct
69 Correct 158 ms 14328 KB Output is correct
70 Correct 156 ms 14204 KB Output is correct
71 Correct 7 ms 4984 KB Output is correct
72 Correct 9 ms 5368 KB Output is correct
73 Correct 9 ms 5368 KB Output is correct
74 Correct 9 ms 5368 KB Output is correct
75 Correct 10 ms 5368 KB Output is correct
76 Correct 9 ms 5368 KB Output is correct
77 Correct 10 ms 5368 KB Output is correct
78 Correct 9 ms 5368 KB Output is correct
79 Correct 9 ms 5368 KB Output is correct
80 Correct 165 ms 14200 KB Output is correct
81 Correct 150 ms 14200 KB Output is correct
82 Correct 142 ms 14328 KB Output is correct
83 Correct 141 ms 14456 KB Output is correct
84 Correct 9 ms 5240 KB Output is correct
85 Correct 9 ms 5240 KB Output is correct
86 Correct 9 ms 5368 KB Output is correct
87 Correct 9 ms 5244 KB Output is correct
88 Correct 9 ms 5368 KB Output is correct
89 Correct 9 ms 5368 KB Output is correct
90 Correct 9 ms 5368 KB Output is correct
91 Correct 9 ms 5368 KB Output is correct
92 Correct 10 ms 5368 KB Output is correct
93 Correct 9 ms 5368 KB Output is correct
94 Correct 7 ms 4984 KB Output is correct
95 Correct 7 ms 4984 KB Output is correct
96 Correct 8 ms 4984 KB Output is correct
97 Correct 7 ms 4984 KB Output is correct
98 Correct 7 ms 5112 KB Output is correct
99 Correct 8 ms 4984 KB Output is correct
100 Correct 8 ms 4984 KB Output is correct
101 Correct 8 ms 4984 KB Output is correct
102 Correct 7 ms 4984 KB Output is correct
103 Correct 7 ms 4984 KB Output is correct
104 Correct 15 ms 6392 KB Output is correct
105 Correct 25 ms 8184 KB Output is correct
106 Correct 8 ms 5112 KB Output is correct
107 Correct 44 ms 10232 KB Output is correct
108 Correct 61 ms 12180 KB Output is correct
109 Correct 8 ms 5112 KB Output is correct
110 Correct 102 ms 14456 KB Output is correct
111 Correct 122 ms 16632 KB Output is correct
112 Correct 8 ms 5240 KB Output is correct
113 Correct 177 ms 20344 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 42 ms 11388 KB Output is correct
2 Incorrect 43 ms 11384 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 91 ms 19192 KB Output is correct
2 Correct 94 ms 19064 KB Output is correct
3 Correct 58 ms 14328 KB Output is correct
4 Correct 17 ms 7160 KB Output is correct
5 Correct 15 ms 6392 KB Output is correct
6 Correct 24 ms 8184 KB Output is correct
7 Correct 8 ms 5112 KB Output is correct
8 Correct 45 ms 10232 KB Output is correct
9 Correct 61 ms 12152 KB Output is correct
10 Correct 8 ms 5112 KB Output is correct
11 Correct 101 ms 14456 KB Output is correct
12 Correct 123 ms 16632 KB Output is correct
13 Correct 8 ms 5112 KB Output is correct
14 Correct 8 ms 5112 KB Output is correct
15 Correct 9 ms 5240 KB Output is correct
16 Correct 9 ms 5368 KB Output is correct
17 Correct 8 ms 5112 KB Output is correct
18 Correct 8 ms 5240 KB Output is correct
19 Correct 9 ms 5368 KB Output is correct
20 Correct 8 ms 5112 KB Output is correct
21 Incorrect 9 ms 5240 KB Output isn't correct
22 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 91 ms 19192 KB Output is correct
2 Correct 94 ms 19064 KB Output is correct
3 Correct 58 ms 14328 KB Output is correct
4 Correct 17 ms 7160 KB Output is correct
5 Correct 15 ms 6392 KB Output is correct
6 Correct 24 ms 8184 KB Output is correct
7 Correct 8 ms 5112 KB Output is correct
8 Correct 45 ms 10232 KB Output is correct
9 Correct 61 ms 12152 KB Output is correct
10 Correct 8 ms 5112 KB Output is correct
11 Correct 101 ms 14456 KB Output is correct
12 Correct 123 ms 16632 KB Output is correct
13 Correct 8 ms 5112 KB Output is correct
14 Correct 8 ms 4980 KB Output is correct
15 Correct 7 ms 4984 KB Output is correct
16 Correct 8 ms 4984 KB Output is correct
17 Correct 7 ms 4984 KB Output is correct
18 Correct 8 ms 4988 KB Output is correct
19 Correct 7 ms 4984 KB Output is correct
20 Correct 7 ms 4984 KB Output is correct
21 Correct 7 ms 4984 KB Output is correct
22 Correct 9 ms 5112 KB Output is correct
23 Correct 7 ms 4984 KB Output is correct
24 Correct 8 ms 5112 KB Output is correct
25 Correct 7 ms 4984 KB Output is correct
26 Correct 8 ms 5112 KB Output is correct
27 Correct 7 ms 4984 KB Output is correct
28 Correct 7 ms 4984 KB Output is correct
29 Correct 7 ms 4984 KB Output is correct
30 Correct 8 ms 4988 KB Output is correct
31 Correct 8 ms 4984 KB Output is correct
32 Correct 7 ms 4984 KB Output is correct
33 Correct 7 ms 5164 KB Output is correct
34 Correct 7 ms 4984 KB Output is correct
35 Correct 8 ms 4984 KB Output is correct
36 Correct 7 ms 4984 KB Output is correct
37 Correct 8 ms 4984 KB Output is correct
38 Correct 8 ms 4984 KB Output is correct
39 Correct 102 ms 19064 KB Output is correct
40 Correct 102 ms 19064 KB Output is correct
41 Correct 57 ms 14328 KB Output is correct
42 Correct 18 ms 7160 KB Output is correct
43 Correct 8 ms 4984 KB Output is correct
44 Correct 8 ms 4984 KB Output is correct
45 Correct 9 ms 5112 KB Output is correct
46 Correct 8 ms 4984 KB Output is correct
47 Correct 8 ms 4984 KB Output is correct
48 Correct 7 ms 4984 KB Output is correct
49 Correct 8 ms 4984 KB Output is correct
50 Correct 7 ms 5112 KB Output is correct
51 Correct 8 ms 5112 KB Output is correct
52 Correct 7 ms 4984 KB Output is correct
53 Correct 8 ms 4984 KB Output is correct
54 Correct 7 ms 4984 KB Output is correct
55 Correct 8 ms 4984 KB Output is correct
56 Correct 7 ms 4984 KB Output is correct
57 Correct 155 ms 14076 KB Output is correct
58 Correct 154 ms 14072 KB Output is correct
59 Correct 153 ms 14332 KB Output is correct
60 Correct 157 ms 14328 KB Output is correct
61 Correct 147 ms 14456 KB Output is correct
62 Correct 148 ms 14456 KB Output is correct
63 Correct 137 ms 14264 KB Output is correct
64 Correct 134 ms 14328 KB Output is correct
65 Correct 141 ms 14348 KB Output is correct
66 Correct 139 ms 14328 KB Output is correct
67 Correct 145 ms 14200 KB Output is correct
68 Correct 151 ms 14204 KB Output is correct
69 Correct 158 ms 14328 KB Output is correct
70 Correct 156 ms 14204 KB Output is correct
71 Correct 7 ms 4984 KB Output is correct
72 Correct 9 ms 5368 KB Output is correct
73 Correct 9 ms 5368 KB Output is correct
74 Correct 9 ms 5368 KB Output is correct
75 Correct 10 ms 5368 KB Output is correct
76 Correct 9 ms 5368 KB Output is correct
77 Correct 10 ms 5368 KB Output is correct
78 Correct 9 ms 5368 KB Output is correct
79 Correct 9 ms 5368 KB Output is correct
80 Correct 165 ms 14200 KB Output is correct
81 Correct 150 ms 14200 KB Output is correct
82 Correct 142 ms 14328 KB Output is correct
83 Correct 141 ms 14456 KB Output is correct
84 Correct 9 ms 5240 KB Output is correct
85 Correct 9 ms 5240 KB Output is correct
86 Correct 9 ms 5368 KB Output is correct
87 Correct 9 ms 5244 KB Output is correct
88 Correct 9 ms 5368 KB Output is correct
89 Correct 9 ms 5368 KB Output is correct
90 Correct 9 ms 5368 KB Output is correct
91 Correct 9 ms 5368 KB Output is correct
92 Correct 10 ms 5368 KB Output is correct
93 Correct 9 ms 5368 KB Output is correct
94 Correct 7 ms 4984 KB Output is correct
95 Correct 7 ms 4984 KB Output is correct
96 Correct 8 ms 4984 KB Output is correct
97 Correct 7 ms 4984 KB Output is correct
98 Correct 7 ms 5112 KB Output is correct
99 Correct 8 ms 4984 KB Output is correct
100 Correct 8 ms 4984 KB Output is correct
101 Correct 8 ms 4984 KB Output is correct
102 Correct 7 ms 4984 KB Output is correct
103 Correct 7 ms 4984 KB Output is correct
104 Correct 15 ms 6392 KB Output is correct
105 Correct 25 ms 8184 KB Output is correct
106 Correct 8 ms 5112 KB Output is correct
107 Correct 44 ms 10232 KB Output is correct
108 Correct 61 ms 12180 KB Output is correct
109 Correct 8 ms 5112 KB Output is correct
110 Correct 102 ms 14456 KB Output is correct
111 Correct 122 ms 16632 KB Output is correct
112 Correct 8 ms 5240 KB Output is correct
113 Correct 177 ms 20344 KB Output is correct
114 Correct 42 ms 11388 KB Output is correct
115 Incorrect 43 ms 11384 KB Output isn't correct
116 Halted 0 ms 0 KB -