답안 #210676

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
210676 2020-03-18T01:45:14 Z peuch 꿈 (IOI13_dreaming) C++17
47 / 100
180 ms 21880 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++){
                 ~~^~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 103 ms 19064 KB Output is correct
2 Correct 94 ms 20088 KB Output is correct
3 Correct 59 ms 15096 KB Output is correct
4 Correct 17 ms 7288 KB Output is correct
5 Correct 15 ms 6392 KB Output is correct
6 Correct 27 ms 8448 KB Output is correct
7 Correct 8 ms 5112 KB Output is correct
8 Correct 43 ms 10616 KB Output is correct
9 Correct 61 ms 12664 KB Output is correct
10 Correct 8 ms 5112 KB Output is correct
11 Correct 103 ms 15480 KB Output is correct
12 Correct 132 ms 17768 KB Output is correct
13 Correct 8 ms 5112 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 103 ms 19064 KB Output is correct
2 Correct 94 ms 20088 KB Output is correct
3 Correct 59 ms 15096 KB Output is correct
4 Correct 17 ms 7288 KB Output is correct
5 Correct 15 ms 6392 KB Output is correct
6 Correct 27 ms 8448 KB Output is correct
7 Correct 8 ms 5112 KB Output is correct
8 Correct 43 ms 10616 KB Output is correct
9 Correct 61 ms 12664 KB Output is correct
10 Correct 8 ms 5112 KB Output is correct
11 Correct 103 ms 15480 KB Output is correct
12 Correct 132 ms 17768 KB Output is correct
13 Correct 8 ms 5112 KB Output is correct
14 Correct 8 ms 4984 KB Output is correct
15 Correct 7 ms 4984 KB Output is correct
16 Correct 7 ms 4984 KB Output is correct
17 Correct 7 ms 4984 KB Output is correct
18 Correct 8 ms 4984 KB Output is correct
19 Correct 7 ms 4984 KB Output is correct
20 Correct 8 ms 4984 KB Output is correct
21 Correct 7 ms 4984 KB Output is correct
22 Correct 8 ms 4984 KB Output is correct
23 Correct 8 ms 5112 KB Output is correct
24 Correct 7 ms 4984 KB Output is correct
25 Correct 7 ms 5112 KB Output is correct
26 Correct 8 ms 4984 KB Output is correct
27 Correct 8 ms 5112 KB Output is correct
28 Correct 8 ms 4984 KB Output is correct
29 Correct 7 ms 4984 KB Output is correct
30 Correct 8 ms 4984 KB Output is correct
31 Correct 8 ms 5112 KB Output is correct
32 Correct 8 ms 5112 KB Output is correct
33 Correct 7 ms 4984 KB Output is correct
34 Correct 7 ms 4984 KB Output is correct
35 Correct 7 ms 4984 KB Output is correct
36 Correct 8 ms 4984 KB Output is correct
37 Correct 8 ms 4984 KB Output is correct
38 Correct 8 ms 4984 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 103 ms 19064 KB Output is correct
2 Correct 94 ms 20088 KB Output is correct
3 Correct 59 ms 15096 KB Output is correct
4 Correct 17 ms 7288 KB Output is correct
5 Correct 15 ms 6392 KB Output is correct
6 Correct 27 ms 8448 KB Output is correct
7 Correct 8 ms 5112 KB Output is correct
8 Correct 43 ms 10616 KB Output is correct
9 Correct 61 ms 12664 KB Output is correct
10 Correct 8 ms 5112 KB Output is correct
11 Correct 103 ms 15480 KB Output is correct
12 Correct 132 ms 17768 KB Output is correct
13 Correct 8 ms 5112 KB Output is correct
14 Correct 8 ms 4984 KB Output is correct
15 Correct 7 ms 4984 KB Output is correct
16 Correct 7 ms 4984 KB Output is correct
17 Correct 7 ms 4984 KB Output is correct
18 Correct 8 ms 4984 KB Output is correct
19 Correct 7 ms 4984 KB Output is correct
20 Correct 8 ms 4984 KB Output is correct
21 Correct 7 ms 4984 KB Output is correct
22 Correct 8 ms 4984 KB Output is correct
23 Correct 8 ms 5112 KB Output is correct
24 Correct 7 ms 4984 KB Output is correct
25 Correct 7 ms 5112 KB Output is correct
26 Correct 8 ms 4984 KB Output is correct
27 Correct 8 ms 5112 KB Output is correct
28 Correct 8 ms 4984 KB Output is correct
29 Correct 7 ms 4984 KB Output is correct
30 Correct 8 ms 4984 KB Output is correct
31 Correct 8 ms 5112 KB Output is correct
32 Correct 8 ms 5112 KB Output is correct
33 Correct 7 ms 4984 KB Output is correct
34 Correct 7 ms 4984 KB Output is correct
35 Correct 7 ms 4984 KB Output is correct
36 Correct 8 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 99 ms 20216 KB Output is correct
40 Correct 97 ms 20088 KB Output is correct
41 Correct 59 ms 15096 KB Output is correct
42 Correct 17 ms 7288 KB Output is correct
43 Correct 8 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 8 ms 4984 KB Output is correct
47 Correct 8 ms 4984 KB Output is correct
48 Correct 8 ms 4984 KB Output is correct
49 Correct 7 ms 4984 KB Output is correct
50 Correct 7 ms 5112 KB Output is correct
51 Correct 7 ms 4988 KB Output is correct
52 Correct 8 ms 4984 KB Output is correct
53 Correct 8 ms 4984 KB Output is correct
54 Correct 8 ms 5068 KB Output is correct
55 Correct 7 ms 4984 KB Output is correct
56 Correct 7 ms 4988 KB Output is correct
57 Correct 155 ms 15456 KB Output is correct
58 Correct 151 ms 15352 KB Output is correct
59 Correct 152 ms 15480 KB Output is correct
60 Correct 148 ms 15532 KB Output is correct
61 Correct 148 ms 15856 KB Output is correct
62 Correct 142 ms 15864 KB Output is correct
63 Correct 135 ms 15480 KB Output is correct
64 Correct 141 ms 15728 KB Output is correct
65 Correct 144 ms 15864 KB Output is correct
66 Correct 138 ms 15736 KB Output is correct
67 Correct 147 ms 15480 KB Output is correct
68 Correct 156 ms 15480 KB Output is correct
69 Correct 163 ms 15736 KB Output is correct
70 Correct 157 ms 15736 KB Output is correct
71 Correct 8 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 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 10 ms 5368 KB Output is correct
79 Correct 9 ms 5368 KB Output is correct
80 Correct 147 ms 15480 KB Output is correct
81 Correct 149 ms 15480 KB Output is correct
82 Correct 158 ms 15736 KB Output is correct
83 Correct 146 ms 15864 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 5240 KB Output is correct
87 Correct 9 ms 5240 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 9 ms 5372 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 4984 KB Output is correct
96 Correct 7 ms 4984 KB Output is correct
97 Correct 8 ms 4984 KB Output is correct
98 Correct 7 ms 4988 KB Output is correct
99 Correct 8 ms 5116 KB Output is correct
100 Correct 7 ms 4984 KB Output is correct
101 Correct 7 ms 4984 KB Output is correct
102 Correct 8 ms 4984 KB Output is correct
103 Correct 8 ms 4984 KB Output is correct
104 Correct 16 ms 6392 KB Output is correct
105 Correct 32 ms 8568 KB Output is correct
106 Correct 8 ms 5112 KB Output is correct
107 Correct 45 ms 10616 KB Output is correct
108 Correct 61 ms 12664 KB Output is correct
109 Correct 8 ms 5112 KB Output is correct
110 Correct 100 ms 15480 KB Output is correct
111 Correct 116 ms 17656 KB Output is correct
112 Correct 8 ms 5112 KB Output is correct
113 Correct 180 ms 21880 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 41 ms 11256 KB Output is correct
2 Incorrect 41 ms 11256 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 103 ms 19064 KB Output is correct
2 Correct 94 ms 20088 KB Output is correct
3 Correct 59 ms 15096 KB Output is correct
4 Correct 17 ms 7288 KB Output is correct
5 Correct 15 ms 6392 KB Output is correct
6 Correct 27 ms 8448 KB Output is correct
7 Correct 8 ms 5112 KB Output is correct
8 Correct 43 ms 10616 KB Output is correct
9 Correct 61 ms 12664 KB Output is correct
10 Correct 8 ms 5112 KB Output is correct
11 Correct 103 ms 15480 KB Output is correct
12 Correct 132 ms 17768 KB Output is correct
13 Correct 8 ms 5112 KB Output is correct
14 Correct 8 ms 5112 KB Output is correct
15 Correct 8 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 9 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 -
# 결과 실행 시간 메모리 Grader output
1 Correct 103 ms 19064 KB Output is correct
2 Correct 94 ms 20088 KB Output is correct
3 Correct 59 ms 15096 KB Output is correct
4 Correct 17 ms 7288 KB Output is correct
5 Correct 15 ms 6392 KB Output is correct
6 Correct 27 ms 8448 KB Output is correct
7 Correct 8 ms 5112 KB Output is correct
8 Correct 43 ms 10616 KB Output is correct
9 Correct 61 ms 12664 KB Output is correct
10 Correct 8 ms 5112 KB Output is correct
11 Correct 103 ms 15480 KB Output is correct
12 Correct 132 ms 17768 KB Output is correct
13 Correct 8 ms 5112 KB Output is correct
14 Correct 8 ms 4984 KB Output is correct
15 Correct 7 ms 4984 KB Output is correct
16 Correct 7 ms 4984 KB Output is correct
17 Correct 7 ms 4984 KB Output is correct
18 Correct 8 ms 4984 KB Output is correct
19 Correct 7 ms 4984 KB Output is correct
20 Correct 8 ms 4984 KB Output is correct
21 Correct 7 ms 4984 KB Output is correct
22 Correct 8 ms 4984 KB Output is correct
23 Correct 8 ms 5112 KB Output is correct
24 Correct 7 ms 4984 KB Output is correct
25 Correct 7 ms 5112 KB Output is correct
26 Correct 8 ms 4984 KB Output is correct
27 Correct 8 ms 5112 KB Output is correct
28 Correct 8 ms 4984 KB Output is correct
29 Correct 7 ms 4984 KB Output is correct
30 Correct 8 ms 4984 KB Output is correct
31 Correct 8 ms 5112 KB Output is correct
32 Correct 8 ms 5112 KB Output is correct
33 Correct 7 ms 4984 KB Output is correct
34 Correct 7 ms 4984 KB Output is correct
35 Correct 7 ms 4984 KB Output is correct
36 Correct 8 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 99 ms 20216 KB Output is correct
40 Correct 97 ms 20088 KB Output is correct
41 Correct 59 ms 15096 KB Output is correct
42 Correct 17 ms 7288 KB Output is correct
43 Correct 8 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 8 ms 4984 KB Output is correct
47 Correct 8 ms 4984 KB Output is correct
48 Correct 8 ms 4984 KB Output is correct
49 Correct 7 ms 4984 KB Output is correct
50 Correct 7 ms 5112 KB Output is correct
51 Correct 7 ms 4988 KB Output is correct
52 Correct 8 ms 4984 KB Output is correct
53 Correct 8 ms 4984 KB Output is correct
54 Correct 8 ms 5068 KB Output is correct
55 Correct 7 ms 4984 KB Output is correct
56 Correct 7 ms 4988 KB Output is correct
57 Correct 155 ms 15456 KB Output is correct
58 Correct 151 ms 15352 KB Output is correct
59 Correct 152 ms 15480 KB Output is correct
60 Correct 148 ms 15532 KB Output is correct
61 Correct 148 ms 15856 KB Output is correct
62 Correct 142 ms 15864 KB Output is correct
63 Correct 135 ms 15480 KB Output is correct
64 Correct 141 ms 15728 KB Output is correct
65 Correct 144 ms 15864 KB Output is correct
66 Correct 138 ms 15736 KB Output is correct
67 Correct 147 ms 15480 KB Output is correct
68 Correct 156 ms 15480 KB Output is correct
69 Correct 163 ms 15736 KB Output is correct
70 Correct 157 ms 15736 KB Output is correct
71 Correct 8 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 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 10 ms 5368 KB Output is correct
79 Correct 9 ms 5368 KB Output is correct
80 Correct 147 ms 15480 KB Output is correct
81 Correct 149 ms 15480 KB Output is correct
82 Correct 158 ms 15736 KB Output is correct
83 Correct 146 ms 15864 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 5240 KB Output is correct
87 Correct 9 ms 5240 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 9 ms 5372 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 4984 KB Output is correct
96 Correct 7 ms 4984 KB Output is correct
97 Correct 8 ms 4984 KB Output is correct
98 Correct 7 ms 4988 KB Output is correct
99 Correct 8 ms 5116 KB Output is correct
100 Correct 7 ms 4984 KB Output is correct
101 Correct 7 ms 4984 KB Output is correct
102 Correct 8 ms 4984 KB Output is correct
103 Correct 8 ms 4984 KB Output is correct
104 Correct 16 ms 6392 KB Output is correct
105 Correct 32 ms 8568 KB Output is correct
106 Correct 8 ms 5112 KB Output is correct
107 Correct 45 ms 10616 KB Output is correct
108 Correct 61 ms 12664 KB Output is correct
109 Correct 8 ms 5112 KB Output is correct
110 Correct 100 ms 15480 KB Output is correct
111 Correct 116 ms 17656 KB Output is correct
112 Correct 8 ms 5112 KB Output is correct
113 Correct 180 ms 21880 KB Output is correct
114 Correct 41 ms 11256 KB Output is correct
115 Incorrect 41 ms 11256 KB Output isn't correct
116 Halted 0 ms 0 KB -