답안 #212216

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
212216 2020-03-22T14:05:12 Z peuch 꿈 (IOI13_dreaming) C++17
47 / 100
187 ms 22008 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");
	int aux = group[0];
	for(int i = 1; i < group.size(); i++){
		ret = max(ret, group[i] + aux + L);
		aux = min(max(group[i], aux + L), max(aux, 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:43: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:55: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:70: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:84:19: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for(int i = 0; i < ar[cur].size(); i++){
                 ~~^~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 89 ms 20216 KB Output is correct
2 Correct 89 ms 20088 KB Output is correct
3 Correct 57 ms 15224 KB Output is correct
4 Correct 17 ms 7296 KB Output is correct
5 Correct 15 ms 6400 KB Output is correct
6 Correct 24 ms 8448 KB Output is correct
7 Correct 7 ms 5120 KB Output is correct
8 Correct 43 ms 10620 KB Output is correct
9 Correct 61 ms 12792 KB Output is correct
10 Correct 7 ms 5120 KB Output is correct
11 Correct 93 ms 15480 KB Output is correct
12 Correct 117 ms 17624 KB Output is correct
13 Correct 8 ms 5120 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 89 ms 20216 KB Output is correct
2 Correct 89 ms 20088 KB Output is correct
3 Correct 57 ms 15224 KB Output is correct
4 Correct 17 ms 7296 KB Output is correct
5 Correct 15 ms 6400 KB Output is correct
6 Correct 24 ms 8448 KB Output is correct
7 Correct 7 ms 5120 KB Output is correct
8 Correct 43 ms 10620 KB Output is correct
9 Correct 61 ms 12792 KB Output is correct
10 Correct 7 ms 5120 KB Output is correct
11 Correct 93 ms 15480 KB Output is correct
12 Correct 117 ms 17624 KB Output is correct
13 Correct 8 ms 5120 KB Output is correct
14 Correct 7 ms 4992 KB Output is correct
15 Correct 7 ms 4992 KB Output is correct
16 Correct 7 ms 5120 KB Output is correct
17 Correct 7 ms 5120 KB Output is correct
18 Correct 7 ms 4992 KB Output is correct
19 Correct 9 ms 4992 KB Output is correct
20 Correct 9 ms 4992 KB Output is correct
21 Correct 7 ms 4992 KB Output is correct
22 Correct 7 ms 5120 KB Output is correct
23 Correct 7 ms 4992 KB Output is correct
24 Correct 7 ms 4992 KB Output is correct
25 Correct 8 ms 5120 KB Output is correct
26 Correct 7 ms 5120 KB Output is correct
27 Correct 8 ms 5120 KB Output is correct
28 Correct 7 ms 4992 KB Output is correct
29 Correct 8 ms 5120 KB Output is correct
30 Correct 8 ms 5120 KB Output is correct
31 Correct 7 ms 4992 KB Output is correct
32 Correct 7 ms 4992 KB Output is correct
33 Correct 7 ms 4992 KB Output is correct
34 Correct 7 ms 4992 KB Output is correct
35 Correct 7 ms 4992 KB Output is correct
36 Correct 8 ms 4992 KB Output is correct
37 Correct 7 ms 4992 KB Output is correct
38 Correct 8 ms 5120 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 89 ms 20216 KB Output is correct
2 Correct 89 ms 20088 KB Output is correct
3 Correct 57 ms 15224 KB Output is correct
4 Correct 17 ms 7296 KB Output is correct
5 Correct 15 ms 6400 KB Output is correct
6 Correct 24 ms 8448 KB Output is correct
7 Correct 7 ms 5120 KB Output is correct
8 Correct 43 ms 10620 KB Output is correct
9 Correct 61 ms 12792 KB Output is correct
10 Correct 7 ms 5120 KB Output is correct
11 Correct 93 ms 15480 KB Output is correct
12 Correct 117 ms 17624 KB Output is correct
13 Correct 8 ms 5120 KB Output is correct
14 Correct 7 ms 4992 KB Output is correct
15 Correct 7 ms 4992 KB Output is correct
16 Correct 7 ms 5120 KB Output is correct
17 Correct 7 ms 5120 KB Output is correct
18 Correct 7 ms 4992 KB Output is correct
19 Correct 9 ms 4992 KB Output is correct
20 Correct 9 ms 4992 KB Output is correct
21 Correct 7 ms 4992 KB Output is correct
22 Correct 7 ms 5120 KB Output is correct
23 Correct 7 ms 4992 KB Output is correct
24 Correct 7 ms 4992 KB Output is correct
25 Correct 8 ms 5120 KB Output is correct
26 Correct 7 ms 5120 KB Output is correct
27 Correct 8 ms 5120 KB Output is correct
28 Correct 7 ms 4992 KB Output is correct
29 Correct 8 ms 5120 KB Output is correct
30 Correct 8 ms 5120 KB Output is correct
31 Correct 7 ms 4992 KB Output is correct
32 Correct 7 ms 4992 KB Output is correct
33 Correct 7 ms 4992 KB Output is correct
34 Correct 7 ms 4992 KB Output is correct
35 Correct 7 ms 4992 KB Output is correct
36 Correct 8 ms 4992 KB Output is correct
37 Correct 7 ms 4992 KB Output is correct
38 Correct 8 ms 5120 KB Output is correct
39 Correct 91 ms 20216 KB Output is correct
40 Correct 90 ms 20216 KB Output is correct
41 Correct 62 ms 15224 KB Output is correct
42 Correct 17 ms 7296 KB Output is correct
43 Correct 8 ms 5120 KB Output is correct
44 Correct 7 ms 4992 KB Output is correct
45 Correct 8 ms 4992 KB Output is correct
46 Correct 7 ms 4992 KB Output is correct
47 Correct 8 ms 4992 KB Output is correct
48 Correct 7 ms 4992 KB Output is correct
49 Correct 5 ms 4992 KB Output is correct
50 Correct 7 ms 4992 KB Output is correct
51 Correct 7 ms 4992 KB Output is correct
52 Correct 7 ms 4992 KB Output is correct
53 Correct 7 ms 4992 KB Output is correct
54 Correct 8 ms 4992 KB Output is correct
55 Correct 8 ms 4992 KB Output is correct
56 Correct 7 ms 4992 KB Output is correct
57 Correct 151 ms 15624 KB Output is correct
58 Correct 187 ms 15356 KB Output is correct
59 Correct 137 ms 15608 KB Output is correct
60 Correct 142 ms 15480 KB Output is correct
61 Correct 145 ms 15864 KB Output is correct
62 Correct 133 ms 15864 KB Output is correct
63 Correct 125 ms 15588 KB Output is correct
64 Correct 128 ms 15480 KB Output is correct
65 Correct 141 ms 15864 KB Output is correct
66 Correct 135 ms 15864 KB Output is correct
67 Correct 144 ms 15704 KB Output is correct
68 Correct 136 ms 15480 KB Output is correct
69 Correct 158 ms 15976 KB Output is correct
70 Correct 142 ms 15864 KB Output is correct
71 Correct 7 ms 4992 KB Output is correct
72 Correct 9 ms 5376 KB Output is correct
73 Correct 9 ms 5376 KB Output is correct
74 Correct 9 ms 5376 KB Output is correct
75 Correct 10 ms 5376 KB Output is correct
76 Correct 9 ms 5376 KB Output is correct
77 Correct 9 ms 5376 KB Output is correct
78 Correct 9 ms 5376 KB Output is correct
79 Correct 9 ms 5376 KB Output is correct
80 Correct 139 ms 15480 KB Output is correct
81 Correct 140 ms 15480 KB Output is correct
82 Correct 173 ms 15916 KB Output is correct
83 Correct 132 ms 15864 KB Output is correct
84 Correct 8 ms 5248 KB Output is correct
85 Correct 8 ms 5248 KB Output is correct
86 Correct 9 ms 5248 KB Output is correct
87 Correct 9 ms 5248 KB Output is correct
88 Correct 9 ms 5376 KB Output is correct
89 Correct 10 ms 5284 KB Output is correct
90 Correct 9 ms 5244 KB Output is correct
91 Correct 9 ms 5376 KB Output is correct
92 Correct 9 ms 5376 KB Output is correct
93 Correct 9 ms 5376 KB Output is correct
94 Correct 7 ms 4992 KB Output is correct
95 Correct 7 ms 4992 KB Output is correct
96 Correct 7 ms 4992 KB Output is correct
97 Correct 7 ms 4992 KB Output is correct
98 Correct 7 ms 5120 KB Output is correct
99 Correct 6 ms 5168 KB Output is correct
100 Correct 7 ms 5120 KB Output is correct
101 Correct 8 ms 5120 KB Output is correct
102 Correct 8 ms 4992 KB Output is correct
103 Correct 7 ms 4992 KB Output is correct
104 Correct 20 ms 6400 KB Output is correct
105 Correct 35 ms 8440 KB Output is correct
106 Correct 8 ms 5120 KB Output is correct
107 Correct 48 ms 10616 KB Output is correct
108 Correct 59 ms 12792 KB Output is correct
109 Correct 7 ms 5120 KB Output is correct
110 Correct 100 ms 15396 KB Output is correct
111 Correct 117 ms 17656 KB Output is correct
112 Correct 8 ms 5120 KB Output is correct
113 Correct 165 ms 22008 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 40 ms 11648 KB Output is correct
2 Incorrect 40 ms 11640 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 89 ms 20216 KB Output is correct
2 Correct 89 ms 20088 KB Output is correct
3 Correct 57 ms 15224 KB Output is correct
4 Correct 17 ms 7296 KB Output is correct
5 Correct 15 ms 6400 KB Output is correct
6 Correct 24 ms 8448 KB Output is correct
7 Correct 7 ms 5120 KB Output is correct
8 Correct 43 ms 10620 KB Output is correct
9 Correct 61 ms 12792 KB Output is correct
10 Correct 7 ms 5120 KB Output is correct
11 Correct 93 ms 15480 KB Output is correct
12 Correct 117 ms 17624 KB Output is correct
13 Correct 8 ms 5120 KB Output is correct
14 Correct 9 ms 5120 KB Output is correct
15 Correct 9 ms 5248 KB Output is correct
16 Correct 10 ms 5376 KB Output is correct
17 Correct 8 ms 5120 KB Output is correct
18 Correct 8 ms 5248 KB Output is correct
19 Correct 11 ms 5376 KB Output is correct
20 Correct 8 ms 5120 KB Output is correct
21 Incorrect 9 ms 5248 KB Output isn't correct
22 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 89 ms 20216 KB Output is correct
2 Correct 89 ms 20088 KB Output is correct
3 Correct 57 ms 15224 KB Output is correct
4 Correct 17 ms 7296 KB Output is correct
5 Correct 15 ms 6400 KB Output is correct
6 Correct 24 ms 8448 KB Output is correct
7 Correct 7 ms 5120 KB Output is correct
8 Correct 43 ms 10620 KB Output is correct
9 Correct 61 ms 12792 KB Output is correct
10 Correct 7 ms 5120 KB Output is correct
11 Correct 93 ms 15480 KB Output is correct
12 Correct 117 ms 17624 KB Output is correct
13 Correct 8 ms 5120 KB Output is correct
14 Correct 7 ms 4992 KB Output is correct
15 Correct 7 ms 4992 KB Output is correct
16 Correct 7 ms 5120 KB Output is correct
17 Correct 7 ms 5120 KB Output is correct
18 Correct 7 ms 4992 KB Output is correct
19 Correct 9 ms 4992 KB Output is correct
20 Correct 9 ms 4992 KB Output is correct
21 Correct 7 ms 4992 KB Output is correct
22 Correct 7 ms 5120 KB Output is correct
23 Correct 7 ms 4992 KB Output is correct
24 Correct 7 ms 4992 KB Output is correct
25 Correct 8 ms 5120 KB Output is correct
26 Correct 7 ms 5120 KB Output is correct
27 Correct 8 ms 5120 KB Output is correct
28 Correct 7 ms 4992 KB Output is correct
29 Correct 8 ms 5120 KB Output is correct
30 Correct 8 ms 5120 KB Output is correct
31 Correct 7 ms 4992 KB Output is correct
32 Correct 7 ms 4992 KB Output is correct
33 Correct 7 ms 4992 KB Output is correct
34 Correct 7 ms 4992 KB Output is correct
35 Correct 7 ms 4992 KB Output is correct
36 Correct 8 ms 4992 KB Output is correct
37 Correct 7 ms 4992 KB Output is correct
38 Correct 8 ms 5120 KB Output is correct
39 Correct 91 ms 20216 KB Output is correct
40 Correct 90 ms 20216 KB Output is correct
41 Correct 62 ms 15224 KB Output is correct
42 Correct 17 ms 7296 KB Output is correct
43 Correct 8 ms 5120 KB Output is correct
44 Correct 7 ms 4992 KB Output is correct
45 Correct 8 ms 4992 KB Output is correct
46 Correct 7 ms 4992 KB Output is correct
47 Correct 8 ms 4992 KB Output is correct
48 Correct 7 ms 4992 KB Output is correct
49 Correct 5 ms 4992 KB Output is correct
50 Correct 7 ms 4992 KB Output is correct
51 Correct 7 ms 4992 KB Output is correct
52 Correct 7 ms 4992 KB Output is correct
53 Correct 7 ms 4992 KB Output is correct
54 Correct 8 ms 4992 KB Output is correct
55 Correct 8 ms 4992 KB Output is correct
56 Correct 7 ms 4992 KB Output is correct
57 Correct 151 ms 15624 KB Output is correct
58 Correct 187 ms 15356 KB Output is correct
59 Correct 137 ms 15608 KB Output is correct
60 Correct 142 ms 15480 KB Output is correct
61 Correct 145 ms 15864 KB Output is correct
62 Correct 133 ms 15864 KB Output is correct
63 Correct 125 ms 15588 KB Output is correct
64 Correct 128 ms 15480 KB Output is correct
65 Correct 141 ms 15864 KB Output is correct
66 Correct 135 ms 15864 KB Output is correct
67 Correct 144 ms 15704 KB Output is correct
68 Correct 136 ms 15480 KB Output is correct
69 Correct 158 ms 15976 KB Output is correct
70 Correct 142 ms 15864 KB Output is correct
71 Correct 7 ms 4992 KB Output is correct
72 Correct 9 ms 5376 KB Output is correct
73 Correct 9 ms 5376 KB Output is correct
74 Correct 9 ms 5376 KB Output is correct
75 Correct 10 ms 5376 KB Output is correct
76 Correct 9 ms 5376 KB Output is correct
77 Correct 9 ms 5376 KB Output is correct
78 Correct 9 ms 5376 KB Output is correct
79 Correct 9 ms 5376 KB Output is correct
80 Correct 139 ms 15480 KB Output is correct
81 Correct 140 ms 15480 KB Output is correct
82 Correct 173 ms 15916 KB Output is correct
83 Correct 132 ms 15864 KB Output is correct
84 Correct 8 ms 5248 KB Output is correct
85 Correct 8 ms 5248 KB Output is correct
86 Correct 9 ms 5248 KB Output is correct
87 Correct 9 ms 5248 KB Output is correct
88 Correct 9 ms 5376 KB Output is correct
89 Correct 10 ms 5284 KB Output is correct
90 Correct 9 ms 5244 KB Output is correct
91 Correct 9 ms 5376 KB Output is correct
92 Correct 9 ms 5376 KB Output is correct
93 Correct 9 ms 5376 KB Output is correct
94 Correct 7 ms 4992 KB Output is correct
95 Correct 7 ms 4992 KB Output is correct
96 Correct 7 ms 4992 KB Output is correct
97 Correct 7 ms 4992 KB Output is correct
98 Correct 7 ms 5120 KB Output is correct
99 Correct 6 ms 5168 KB Output is correct
100 Correct 7 ms 5120 KB Output is correct
101 Correct 8 ms 5120 KB Output is correct
102 Correct 8 ms 4992 KB Output is correct
103 Correct 7 ms 4992 KB Output is correct
104 Correct 20 ms 6400 KB Output is correct
105 Correct 35 ms 8440 KB Output is correct
106 Correct 8 ms 5120 KB Output is correct
107 Correct 48 ms 10616 KB Output is correct
108 Correct 59 ms 12792 KB Output is correct
109 Correct 7 ms 5120 KB Output is correct
110 Correct 100 ms 15396 KB Output is correct
111 Correct 117 ms 17656 KB Output is correct
112 Correct 8 ms 5120 KB Output is correct
113 Correct 165 ms 22008 KB Output is correct
114 Correct 40 ms 11648 KB Output is correct
115 Incorrect 40 ms 11640 KB Output isn't correct
116 Halted 0 ms 0 KB -