Submission #210681

# Submission time Handle Problem Language Result Execution time Memory
210681 2020-03-18T01:58:32 Z peuch Dreaming (IOI13_dreaming) C++17
47 / 100
229 ms 20216 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<pair<int, int> > group;

int dfs1(int cur);
int dfs2(int cur);
pair<int, 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");
	for(int i = 1; i < group.size(); i++){
		ar[group[i].second].push_back(group[i - 1].second);
		ar[group[i - 1].second].push_back(group[i].second);
		wg[group[i].second].push_back(L);
		wg[group[i - 1].second].push_back(L);
		if(max(group[i].first, group[i - 1].first + L) < max(group[i - 1].first, group[i].first + L)){
			group[i].first = max(group[i].first, group[i - 1].first + L);
			group[i].second = group[i].first;
		}
		else{
			group[i].first = max(group[i - 1].first, group[i].first + L);
			group[i].second = group[i - 1].first;
		}
	}
	int side1 = dfs1(0);
	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);
    return longDist[0][side2];
}

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;
}

pair<int, int> dfs3(int cur){
	marc[cur] = 3;
	int ret = cur;
	int auxRet = 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;
		pair<int, int> dfsVal = dfs3(viz);
		if(dfsVal.first < auxRet) ret = dfsVal.second, auxRet = dfsVal.first;
 	} 
 	// printf("%d max(%d %d) -> %d\n", cur, longDist[0][cur], longDist[1][cur], ret);
 	return make_pair(auxRet, ret);
}

Compilation message

dreaming.cpp: In function 'int travelTime(int, int, int, int*, int*, int*)':
dreaming.cpp:42:19: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for(int i = 1; i < group.size(); i++){
                 ~~^~~~~~~~~~~~~~
dreaming.cpp:25:6: warning: unused variable 'ret' [-Wunused-variable]
  int ret = 0;
      ^~~
dreaming.cpp: In function 'int dfs1(int)':
dreaming.cpp:69: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:84:19: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for(int i = 0; i < ar[cur].size(); i++){
                 ~~^~~~~~~~~~~~~~~~
dreaming.cpp: In function 'std::pair<int, int> dfs3(int)':
dreaming.cpp:99: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 108 ms 18936 KB Output is correct
2 Correct 110 ms 18936 KB Output is correct
3 Correct 84 ms 14196 KB Output is correct
4 Correct 20 ms 7160 KB Output is correct
5 Correct 16 ms 6264 KB Output is correct
6 Correct 26 ms 8056 KB Output is correct
7 Correct 8 ms 5112 KB Output is correct
8 Correct 51 ms 10104 KB Output is correct
9 Correct 73 ms 12024 KB Output is correct
10 Correct 8 ms 5116 KB Output is correct
11 Correct 155 ms 14332 KB Output is correct
12 Correct 153 ms 16504 KB Output is correct
13 Correct 8 ms 5112 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 108 ms 18936 KB Output is correct
2 Correct 110 ms 18936 KB Output is correct
3 Correct 84 ms 14196 KB Output is correct
4 Correct 20 ms 7160 KB Output is correct
5 Correct 16 ms 6264 KB Output is correct
6 Correct 26 ms 8056 KB Output is correct
7 Correct 8 ms 5112 KB Output is correct
8 Correct 51 ms 10104 KB Output is correct
9 Correct 73 ms 12024 KB Output is correct
10 Correct 8 ms 5116 KB Output is correct
11 Correct 155 ms 14332 KB Output is correct
12 Correct 153 ms 16504 KB Output is correct
13 Correct 8 ms 5112 KB Output is correct
14 Correct 7 ms 4984 KB Output is correct
15 Correct 8 ms 5112 KB Output is correct
16 Correct 11 ms 4984 KB Output is correct
17 Correct 11 ms 5112 KB Output is correct
18 Correct 7 ms 4984 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 5112 KB Output is correct
22 Correct 7 ms 4984 KB Output is correct
23 Correct 7 ms 4984 KB Output is correct
24 Correct 8 ms 4988 KB Output is correct
25 Correct 7 ms 4984 KB Output is correct
26 Correct 7 ms 4984 KB Output is correct
27 Correct 8 ms 4984 KB Output is correct
28 Correct 8 ms 4984 KB Output is correct
29 Correct 8 ms 4988 KB Output is correct
30 Correct 9 ms 4984 KB Output is correct
31 Correct 7 ms 4984 KB Output is correct
32 Correct 8 ms 4984 KB Output is correct
33 Correct 7 ms 4984 KB Output is correct
34 Correct 8 ms 4984 KB Output is correct
35 Correct 7 ms 4984 KB Output is correct
36 Correct 7 ms 4984 KB Output is correct
37 Correct 7 ms 4984 KB Output is correct
38 Correct 8 ms 4984 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 108 ms 18936 KB Output is correct
2 Correct 110 ms 18936 KB Output is correct
3 Correct 84 ms 14196 KB Output is correct
4 Correct 20 ms 7160 KB Output is correct
5 Correct 16 ms 6264 KB Output is correct
6 Correct 26 ms 8056 KB Output is correct
7 Correct 8 ms 5112 KB Output is correct
8 Correct 51 ms 10104 KB Output is correct
9 Correct 73 ms 12024 KB Output is correct
10 Correct 8 ms 5116 KB Output is correct
11 Correct 155 ms 14332 KB Output is correct
12 Correct 153 ms 16504 KB Output is correct
13 Correct 8 ms 5112 KB Output is correct
14 Correct 7 ms 4984 KB Output is correct
15 Correct 8 ms 5112 KB Output is correct
16 Correct 11 ms 4984 KB Output is correct
17 Correct 11 ms 5112 KB Output is correct
18 Correct 7 ms 4984 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 5112 KB Output is correct
22 Correct 7 ms 4984 KB Output is correct
23 Correct 7 ms 4984 KB Output is correct
24 Correct 8 ms 4988 KB Output is correct
25 Correct 7 ms 4984 KB Output is correct
26 Correct 7 ms 4984 KB Output is correct
27 Correct 8 ms 4984 KB Output is correct
28 Correct 8 ms 4984 KB Output is correct
29 Correct 8 ms 4988 KB Output is correct
30 Correct 9 ms 4984 KB Output is correct
31 Correct 7 ms 4984 KB Output is correct
32 Correct 8 ms 4984 KB Output is correct
33 Correct 7 ms 4984 KB Output is correct
34 Correct 8 ms 4984 KB Output is correct
35 Correct 7 ms 4984 KB Output is correct
36 Correct 7 ms 4984 KB Output is correct
37 Correct 7 ms 4984 KB Output is correct
38 Correct 8 ms 4984 KB Output is correct
39 Correct 112 ms 18936 KB Output is correct
40 Correct 118 ms 18936 KB Output is correct
41 Correct 66 ms 14124 KB Output is correct
42 Correct 17 ms 7036 KB Output is correct
43 Correct 7 ms 4984 KB Output is correct
44 Correct 7 ms 4984 KB Output is correct
45 Correct 7 ms 4984 KB Output is correct
46 Correct 7 ms 4984 KB Output is correct
47 Correct 7 ms 5112 KB Output is correct
48 Correct 8 ms 4984 KB Output is correct
49 Correct 7 ms 5112 KB Output is correct
50 Correct 8 ms 4984 KB Output is correct
51 Correct 8 ms 5112 KB Output is correct
52 Correct 7 ms 4984 KB Output is correct
53 Correct 7 ms 4984 KB Output is correct
54 Correct 7 ms 5112 KB Output is correct
55 Correct 7 ms 4984 KB Output is correct
56 Correct 8 ms 4984 KB Output is correct
57 Correct 195 ms 13944 KB Output is correct
58 Correct 182 ms 13816 KB Output is correct
59 Correct 185 ms 14200 KB Output is correct
60 Correct 179 ms 14300 KB Output is correct
61 Correct 173 ms 14456 KB Output is correct
62 Correct 170 ms 14328 KB Output is correct
63 Correct 170 ms 14200 KB Output is correct
64 Correct 171 ms 14184 KB Output is correct
65 Correct 168 ms 14200 KB Output is correct
66 Correct 167 ms 14200 KB Output is correct
67 Correct 183 ms 14072 KB Output is correct
68 Correct 184 ms 14200 KB Output is correct
69 Correct 183 ms 14200 KB Output is correct
70 Correct 197 ms 14308 KB Output is correct
71 Correct 7 ms 4984 KB Output is correct
72 Correct 10 ms 5368 KB Output is correct
73 Correct 10 ms 5368 KB Output is correct
74 Correct 10 ms 5372 KB Output is correct
75 Correct 10 ms 5368 KB Output is correct
76 Correct 10 ms 5240 KB Output is correct
77 Correct 10 ms 5244 KB Output is correct
78 Correct 10 ms 5368 KB Output is correct
79 Correct 10 ms 5368 KB Output is correct
80 Correct 189 ms 14200 KB Output is correct
81 Correct 181 ms 14072 KB Output is correct
82 Correct 171 ms 14328 KB Output is correct
83 Correct 177 ms 14328 KB Output is correct
84 Correct 9 ms 5240 KB Output is correct
85 Correct 9 ms 5244 KB Output is correct
86 Correct 9 ms 5240 KB Output is correct
87 Correct 9 ms 5240 KB Output is correct
88 Correct 9 ms 5244 KB Output is correct
89 Correct 9 ms 5240 KB Output is correct
90 Correct 9 ms 5240 KB Output is correct
91 Correct 10 ms 5368 KB Output is correct
92 Correct 9 ms 5240 KB Output is correct
93 Correct 9 ms 5368 KB Output is correct
94 Correct 8 ms 4984 KB Output is correct
95 Correct 8 ms 5112 KB Output is correct
96 Correct 8 ms 4984 KB Output is correct
97 Correct 7 ms 5112 KB Output is correct
98 Correct 8 ms 4984 KB Output is correct
99 Correct 7 ms 5112 KB Output is correct
100 Correct 7 ms 5112 KB Output is correct
101 Correct 7 ms 4984 KB Output is correct
102 Correct 7 ms 4984 KB Output is correct
103 Correct 7 ms 5112 KB Output is correct
104 Correct 17 ms 6264 KB Output is correct
105 Correct 27 ms 8056 KB Output is correct
106 Correct 8 ms 5112 KB Output is correct
107 Correct 50 ms 10104 KB Output is correct
108 Correct 80 ms 12024 KB Output is correct
109 Correct 8 ms 5116 KB Output is correct
110 Correct 123 ms 14328 KB Output is correct
111 Correct 165 ms 16504 KB Output is correct
112 Correct 8 ms 5240 KB Output is correct
113 Correct 229 ms 20216 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 54 ms 13664 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 108 ms 18936 KB Output is correct
2 Correct 110 ms 18936 KB Output is correct
3 Correct 84 ms 14196 KB Output is correct
4 Correct 20 ms 7160 KB Output is correct
5 Correct 16 ms 6264 KB Output is correct
6 Correct 26 ms 8056 KB Output is correct
7 Correct 8 ms 5112 KB Output is correct
8 Correct 51 ms 10104 KB Output is correct
9 Correct 73 ms 12024 KB Output is correct
10 Correct 8 ms 5116 KB Output is correct
11 Correct 155 ms 14332 KB Output is correct
12 Correct 153 ms 16504 KB Output is correct
13 Correct 8 ms 5112 KB Output is correct
14 Incorrect 9 ms 5112 KB Output isn't correct
15 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 108 ms 18936 KB Output is correct
2 Correct 110 ms 18936 KB Output is correct
3 Correct 84 ms 14196 KB Output is correct
4 Correct 20 ms 7160 KB Output is correct
5 Correct 16 ms 6264 KB Output is correct
6 Correct 26 ms 8056 KB Output is correct
7 Correct 8 ms 5112 KB Output is correct
8 Correct 51 ms 10104 KB Output is correct
9 Correct 73 ms 12024 KB Output is correct
10 Correct 8 ms 5116 KB Output is correct
11 Correct 155 ms 14332 KB Output is correct
12 Correct 153 ms 16504 KB Output is correct
13 Correct 8 ms 5112 KB Output is correct
14 Correct 7 ms 4984 KB Output is correct
15 Correct 8 ms 5112 KB Output is correct
16 Correct 11 ms 4984 KB Output is correct
17 Correct 11 ms 5112 KB Output is correct
18 Correct 7 ms 4984 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 5112 KB Output is correct
22 Correct 7 ms 4984 KB Output is correct
23 Correct 7 ms 4984 KB Output is correct
24 Correct 8 ms 4988 KB Output is correct
25 Correct 7 ms 4984 KB Output is correct
26 Correct 7 ms 4984 KB Output is correct
27 Correct 8 ms 4984 KB Output is correct
28 Correct 8 ms 4984 KB Output is correct
29 Correct 8 ms 4988 KB Output is correct
30 Correct 9 ms 4984 KB Output is correct
31 Correct 7 ms 4984 KB Output is correct
32 Correct 8 ms 4984 KB Output is correct
33 Correct 7 ms 4984 KB Output is correct
34 Correct 8 ms 4984 KB Output is correct
35 Correct 7 ms 4984 KB Output is correct
36 Correct 7 ms 4984 KB Output is correct
37 Correct 7 ms 4984 KB Output is correct
38 Correct 8 ms 4984 KB Output is correct
39 Correct 112 ms 18936 KB Output is correct
40 Correct 118 ms 18936 KB Output is correct
41 Correct 66 ms 14124 KB Output is correct
42 Correct 17 ms 7036 KB Output is correct
43 Correct 7 ms 4984 KB Output is correct
44 Correct 7 ms 4984 KB Output is correct
45 Correct 7 ms 4984 KB Output is correct
46 Correct 7 ms 4984 KB Output is correct
47 Correct 7 ms 5112 KB Output is correct
48 Correct 8 ms 4984 KB Output is correct
49 Correct 7 ms 5112 KB Output is correct
50 Correct 8 ms 4984 KB Output is correct
51 Correct 8 ms 5112 KB Output is correct
52 Correct 7 ms 4984 KB Output is correct
53 Correct 7 ms 4984 KB Output is correct
54 Correct 7 ms 5112 KB Output is correct
55 Correct 7 ms 4984 KB Output is correct
56 Correct 8 ms 4984 KB Output is correct
57 Correct 195 ms 13944 KB Output is correct
58 Correct 182 ms 13816 KB Output is correct
59 Correct 185 ms 14200 KB Output is correct
60 Correct 179 ms 14300 KB Output is correct
61 Correct 173 ms 14456 KB Output is correct
62 Correct 170 ms 14328 KB Output is correct
63 Correct 170 ms 14200 KB Output is correct
64 Correct 171 ms 14184 KB Output is correct
65 Correct 168 ms 14200 KB Output is correct
66 Correct 167 ms 14200 KB Output is correct
67 Correct 183 ms 14072 KB Output is correct
68 Correct 184 ms 14200 KB Output is correct
69 Correct 183 ms 14200 KB Output is correct
70 Correct 197 ms 14308 KB Output is correct
71 Correct 7 ms 4984 KB Output is correct
72 Correct 10 ms 5368 KB Output is correct
73 Correct 10 ms 5368 KB Output is correct
74 Correct 10 ms 5372 KB Output is correct
75 Correct 10 ms 5368 KB Output is correct
76 Correct 10 ms 5240 KB Output is correct
77 Correct 10 ms 5244 KB Output is correct
78 Correct 10 ms 5368 KB Output is correct
79 Correct 10 ms 5368 KB Output is correct
80 Correct 189 ms 14200 KB Output is correct
81 Correct 181 ms 14072 KB Output is correct
82 Correct 171 ms 14328 KB Output is correct
83 Correct 177 ms 14328 KB Output is correct
84 Correct 9 ms 5240 KB Output is correct
85 Correct 9 ms 5244 KB Output is correct
86 Correct 9 ms 5240 KB Output is correct
87 Correct 9 ms 5240 KB Output is correct
88 Correct 9 ms 5244 KB Output is correct
89 Correct 9 ms 5240 KB Output is correct
90 Correct 9 ms 5240 KB Output is correct
91 Correct 10 ms 5368 KB Output is correct
92 Correct 9 ms 5240 KB Output is correct
93 Correct 9 ms 5368 KB Output is correct
94 Correct 8 ms 4984 KB Output is correct
95 Correct 8 ms 5112 KB Output is correct
96 Correct 8 ms 4984 KB Output is correct
97 Correct 7 ms 5112 KB Output is correct
98 Correct 8 ms 4984 KB Output is correct
99 Correct 7 ms 5112 KB Output is correct
100 Correct 7 ms 5112 KB Output is correct
101 Correct 7 ms 4984 KB Output is correct
102 Correct 7 ms 4984 KB Output is correct
103 Correct 7 ms 5112 KB Output is correct
104 Correct 17 ms 6264 KB Output is correct
105 Correct 27 ms 8056 KB Output is correct
106 Correct 8 ms 5112 KB Output is correct
107 Correct 50 ms 10104 KB Output is correct
108 Correct 80 ms 12024 KB Output is correct
109 Correct 8 ms 5116 KB Output is correct
110 Correct 123 ms 14328 KB Output is correct
111 Correct 165 ms 16504 KB Output is correct
112 Correct 8 ms 5240 KB Output is correct
113 Correct 229 ms 20216 KB Output is correct
114 Incorrect 54 ms 13664 KB Output isn't correct
115 Halted 0 ms 0 KB -