답안 #171045

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
171045 2019-12-27T08:07:20 Z dennisstar 꿈 (IOI13_dreaming) C++11
47 / 100
194 ms 31668 KB
#include "dreaming.h"
#include <bits/stdc++.h>
#define fi first
#define se second
#define ryan bear
#define all(V) ((V).begin()), ((V).end())
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef long double ld;
typedef vector<int> vim;
typedef vector<ll> vlm;

int N, M, L;
int *A, *B, *T;
vim V[100010], C[100010];
vector<pii> D1[100010];
vim D2[100010];
int chk[100010];
vim ar;
int mx;

int dfs1(int now, int par, int dep) {
	chk[now]=1;
	for (int i=0; i<V[now].size(); i++) {
		if (chk[V[now][i]]) continue;
		D1[now].push_back({dfs1(V[now][i], now, dep+C[now][i])-dep, V[now][i]});
	}
	int ret=dep;
	for (int i=0; i<D1[now].size(); i++) ret=max(ret, D1[now][i].fi+dep);
	return ret;
}

int dfs2(int now, int dep) {
	chk[now]=1;
	if (!D1[now].size()) return dep;
	mx=max(mx, dep+D1[now][0].fi);
	if (D1[now].size()>1) mx=max(mx, D1[now][0].fi+D1[now][1].fi);
	int ret=max(dep, D1[now][0].fi);
	for (int i=0; i<V[now].size(); i++) {
		if (chk[V[now][i]]) continue;
		ret=min(ret, dfs2(V[now][i], max(dep, (D1[now][0].se==V[now][i]?(D1[now].size()>1?D1[now][1].fi:0):D1[now][0].fi))+C[now][i]));
	}
	return ret;
}

int travelTime(int N_, int M_, int L_, int A_[], int B_[], int T_[]) {
	N=N_; M=M_; L=L_; A=A_; B=B_; T=T_;
	for (int i=0; i<M; i++) {
		V[A[i]+1].push_back(B[i]+1);
		V[B[i]+1].push_back(A[i]+1);
		C[A[i]+1].push_back(T[i]);
		C[B[i]+1].push_back(T[i]);
	}
	for (int i=1; i<=N; i++) if (!chk[i]) {dfs1(i, 0, 0);}
	for (int i=1; i<=N; i++) sort(all(D1[i]), [](pii x1, pii x2){return x1.fi>x2.fi;});
	for (int i=1; i<=N; i++) chk[i]=0;
	for (int i=1; i<=N; i++) if (!chk[i]) {ar.push_back(dfs2(i, 0));}
	sort(all(ar), [](int x1, int x2){return x1>x2;});
	if (ar.size()==1) return mx;
	else return max(mx, ar[0]+ar[1]+L);
}

Compilation message

dreaming.cpp: In function 'int dfs1(int, int, int)':
dreaming.cpp:26:17: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for (int i=0; i<V[now].size(); i++) {
                ~^~~~~~~~~~~~~~
dreaming.cpp:31:17: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for (int i=0; i<D1[now].size(); i++) ret=max(ret, D1[now][i].fi+dep);
                ~^~~~~~~~~~~~~~~
dreaming.cpp: In function 'int dfs2(int, int)':
dreaming.cpp:41:17: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for (int i=0; i<V[now].size(); i++) {
                ~^~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 123 ms 24568 KB Output is correct
2 Correct 118 ms 25368 KB Output is correct
3 Correct 82 ms 22116 KB Output is correct
4 Correct 26 ms 11996 KB Output is correct
5 Correct 26 ms 11384 KB Output is correct
6 Correct 32 ms 13304 KB Output is correct
7 Correct 11 ms 9848 KB Output is correct
8 Correct 60 ms 16504 KB Output is correct
9 Correct 74 ms 19704 KB Output is correct
10 Correct 11 ms 9848 KB Output is correct
11 Correct 161 ms 21624 KB Output is correct
12 Correct 137 ms 23544 KB Output is correct
13 Correct 11 ms 9848 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 123 ms 24568 KB Output is correct
2 Correct 118 ms 25368 KB Output is correct
3 Correct 82 ms 22116 KB Output is correct
4 Correct 26 ms 11996 KB Output is correct
5 Correct 26 ms 11384 KB Output is correct
6 Correct 32 ms 13304 KB Output is correct
7 Correct 11 ms 9848 KB Output is correct
8 Correct 60 ms 16504 KB Output is correct
9 Correct 74 ms 19704 KB Output is correct
10 Correct 11 ms 9848 KB Output is correct
11 Correct 161 ms 21624 KB Output is correct
12 Correct 137 ms 23544 KB Output is correct
13 Correct 11 ms 9848 KB Output is correct
14 Correct 10 ms 9720 KB Output is correct
15 Correct 10 ms 9720 KB Output is correct
16 Correct 10 ms 9720 KB Output is correct
17 Correct 10 ms 9720 KB Output is correct
18 Correct 10 ms 9720 KB Output is correct
19 Correct 10 ms 9720 KB Output is correct
20 Correct 10 ms 9720 KB Output is correct
21 Correct 10 ms 9720 KB Output is correct
22 Correct 10 ms 9720 KB Output is correct
23 Correct 11 ms 9720 KB Output is correct
24 Correct 10 ms 9720 KB Output is correct
25 Correct 10 ms 9720 KB Output is correct
26 Correct 11 ms 9740 KB Output is correct
27 Correct 10 ms 9720 KB Output is correct
28 Correct 10 ms 9720 KB Output is correct
29 Correct 10 ms 9704 KB Output is correct
30 Correct 10 ms 9720 KB Output is correct
31 Correct 10 ms 9720 KB Output is correct
32 Correct 10 ms 9720 KB Output is correct
33 Correct 10 ms 9720 KB Output is correct
34 Correct 10 ms 9720 KB Output is correct
35 Correct 10 ms 9720 KB Output is correct
36 Correct 11 ms 9720 KB Output is correct
37 Correct 10 ms 9720 KB Output is correct
38 Correct 10 ms 9720 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 123 ms 24568 KB Output is correct
2 Correct 118 ms 25368 KB Output is correct
3 Correct 82 ms 22116 KB Output is correct
4 Correct 26 ms 11996 KB Output is correct
5 Correct 26 ms 11384 KB Output is correct
6 Correct 32 ms 13304 KB Output is correct
7 Correct 11 ms 9848 KB Output is correct
8 Correct 60 ms 16504 KB Output is correct
9 Correct 74 ms 19704 KB Output is correct
10 Correct 11 ms 9848 KB Output is correct
11 Correct 161 ms 21624 KB Output is correct
12 Correct 137 ms 23544 KB Output is correct
13 Correct 11 ms 9848 KB Output is correct
14 Correct 10 ms 9720 KB Output is correct
15 Correct 10 ms 9720 KB Output is correct
16 Correct 10 ms 9720 KB Output is correct
17 Correct 10 ms 9720 KB Output is correct
18 Correct 10 ms 9720 KB Output is correct
19 Correct 10 ms 9720 KB Output is correct
20 Correct 10 ms 9720 KB Output is correct
21 Correct 10 ms 9720 KB Output is correct
22 Correct 10 ms 9720 KB Output is correct
23 Correct 11 ms 9720 KB Output is correct
24 Correct 10 ms 9720 KB Output is correct
25 Correct 10 ms 9720 KB Output is correct
26 Correct 11 ms 9740 KB Output is correct
27 Correct 10 ms 9720 KB Output is correct
28 Correct 10 ms 9720 KB Output is correct
29 Correct 10 ms 9704 KB Output is correct
30 Correct 10 ms 9720 KB Output is correct
31 Correct 10 ms 9720 KB Output is correct
32 Correct 10 ms 9720 KB Output is correct
33 Correct 10 ms 9720 KB Output is correct
34 Correct 10 ms 9720 KB Output is correct
35 Correct 10 ms 9720 KB Output is correct
36 Correct 11 ms 9720 KB Output is correct
37 Correct 10 ms 9720 KB Output is correct
38 Correct 10 ms 9720 KB Output is correct
39 Correct 142 ms 25884 KB Output is correct
40 Correct 131 ms 25308 KB Output is correct
41 Correct 83 ms 22004 KB Output is correct
42 Correct 23 ms 12024 KB Output is correct
43 Correct 10 ms 9720 KB Output is correct
44 Correct 10 ms 9720 KB Output is correct
45 Correct 10 ms 9720 KB Output is correct
46 Correct 11 ms 9720 KB Output is correct
47 Correct 11 ms 9720 KB Output is correct
48 Correct 10 ms 9720 KB Output is correct
49 Correct 10 ms 9720 KB Output is correct
50 Correct 11 ms 9744 KB Output is correct
51 Correct 10 ms 9720 KB Output is correct
52 Correct 10 ms 9720 KB Output is correct
53 Correct 11 ms 9812 KB Output is correct
54 Correct 11 ms 9692 KB Output is correct
55 Correct 10 ms 9720 KB Output is correct
56 Correct 10 ms 9720 KB Output is correct
57 Correct 157 ms 21276 KB Output is correct
58 Correct 156 ms 21116 KB Output is correct
59 Correct 168 ms 21496 KB Output is correct
60 Correct 169 ms 21232 KB Output is correct
61 Correct 161 ms 21268 KB Output is correct
62 Correct 164 ms 21352 KB Output is correct
63 Correct 140 ms 21112 KB Output is correct
64 Correct 143 ms 21116 KB Output is correct
65 Correct 141 ms 21368 KB Output is correct
66 Correct 151 ms 21368 KB Output is correct
67 Correct 160 ms 21240 KB Output is correct
68 Correct 184 ms 21404 KB Output is correct
69 Correct 152 ms 21496 KB Output is correct
70 Correct 155 ms 21496 KB Output is correct
71 Correct 10 ms 9720 KB Output is correct
72 Correct 13 ms 10152 KB Output is correct
73 Correct 13 ms 10108 KB Output is correct
74 Correct 13 ms 10104 KB Output is correct
75 Correct 12 ms 10104 KB Output is correct
76 Correct 13 ms 10104 KB Output is correct
77 Correct 13 ms 10092 KB Output is correct
78 Correct 13 ms 10076 KB Output is correct
79 Correct 15 ms 10104 KB Output is correct
80 Correct 169 ms 21240 KB Output is correct
81 Correct 164 ms 21364 KB Output is correct
82 Correct 166 ms 21352 KB Output is correct
83 Correct 154 ms 21248 KB Output is correct
84 Correct 12 ms 9976 KB Output is correct
85 Correct 12 ms 9976 KB Output is correct
86 Correct 12 ms 9976 KB Output is correct
87 Correct 12 ms 9976 KB Output is correct
88 Correct 12 ms 10104 KB Output is correct
89 Correct 13 ms 10044 KB Output is correct
90 Correct 13 ms 9976 KB Output is correct
91 Correct 13 ms 10076 KB Output is correct
92 Correct 13 ms 10104 KB Output is correct
93 Correct 12 ms 10104 KB Output is correct
94 Correct 10 ms 9720 KB Output is correct
95 Correct 10 ms 9720 KB Output is correct
96 Correct 10 ms 9720 KB Output is correct
97 Correct 10 ms 9724 KB Output is correct
98 Correct 10 ms 9748 KB Output is correct
99 Correct 10 ms 9720 KB Output is correct
100 Correct 11 ms 9720 KB Output is correct
101 Correct 10 ms 9692 KB Output is correct
102 Correct 10 ms 9720 KB Output is correct
103 Correct 11 ms 9720 KB Output is correct
104 Correct 23 ms 11256 KB Output is correct
105 Correct 35 ms 13248 KB Output is correct
106 Correct 10 ms 9720 KB Output is correct
107 Correct 62 ms 16472 KB Output is correct
108 Correct 75 ms 19500 KB Output is correct
109 Correct 11 ms 9848 KB Output is correct
110 Correct 106 ms 21648 KB Output is correct
111 Correct 131 ms 23516 KB Output is correct
112 Correct 11 ms 9848 KB Output is correct
113 Correct 194 ms 31668 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 60 ms 15696 KB Output is correct
2 Incorrect 62 ms 15736 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 123 ms 24568 KB Output is correct
2 Correct 118 ms 25368 KB Output is correct
3 Correct 82 ms 22116 KB Output is correct
4 Correct 26 ms 11996 KB Output is correct
5 Correct 26 ms 11384 KB Output is correct
6 Correct 32 ms 13304 KB Output is correct
7 Correct 11 ms 9848 KB Output is correct
8 Correct 60 ms 16504 KB Output is correct
9 Correct 74 ms 19704 KB Output is correct
10 Correct 11 ms 9848 KB Output is correct
11 Correct 161 ms 21624 KB Output is correct
12 Correct 137 ms 23544 KB Output is correct
13 Correct 11 ms 9848 KB Output is correct
14 Correct 11 ms 9848 KB Output is correct
15 Correct 12 ms 9980 KB Output is correct
16 Correct 13 ms 9976 KB Output is correct
17 Correct 11 ms 9816 KB Output is correct
18 Correct 11 ms 9976 KB Output is correct
19 Correct 13 ms 10104 KB Output is correct
20 Incorrect 11 ms 9848 KB Output isn't correct
21 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 123 ms 24568 KB Output is correct
2 Correct 118 ms 25368 KB Output is correct
3 Correct 82 ms 22116 KB Output is correct
4 Correct 26 ms 11996 KB Output is correct
5 Correct 26 ms 11384 KB Output is correct
6 Correct 32 ms 13304 KB Output is correct
7 Correct 11 ms 9848 KB Output is correct
8 Correct 60 ms 16504 KB Output is correct
9 Correct 74 ms 19704 KB Output is correct
10 Correct 11 ms 9848 KB Output is correct
11 Correct 161 ms 21624 KB Output is correct
12 Correct 137 ms 23544 KB Output is correct
13 Correct 11 ms 9848 KB Output is correct
14 Correct 10 ms 9720 KB Output is correct
15 Correct 10 ms 9720 KB Output is correct
16 Correct 10 ms 9720 KB Output is correct
17 Correct 10 ms 9720 KB Output is correct
18 Correct 10 ms 9720 KB Output is correct
19 Correct 10 ms 9720 KB Output is correct
20 Correct 10 ms 9720 KB Output is correct
21 Correct 10 ms 9720 KB Output is correct
22 Correct 10 ms 9720 KB Output is correct
23 Correct 11 ms 9720 KB Output is correct
24 Correct 10 ms 9720 KB Output is correct
25 Correct 10 ms 9720 KB Output is correct
26 Correct 11 ms 9740 KB Output is correct
27 Correct 10 ms 9720 KB Output is correct
28 Correct 10 ms 9720 KB Output is correct
29 Correct 10 ms 9704 KB Output is correct
30 Correct 10 ms 9720 KB Output is correct
31 Correct 10 ms 9720 KB Output is correct
32 Correct 10 ms 9720 KB Output is correct
33 Correct 10 ms 9720 KB Output is correct
34 Correct 10 ms 9720 KB Output is correct
35 Correct 10 ms 9720 KB Output is correct
36 Correct 11 ms 9720 KB Output is correct
37 Correct 10 ms 9720 KB Output is correct
38 Correct 10 ms 9720 KB Output is correct
39 Correct 142 ms 25884 KB Output is correct
40 Correct 131 ms 25308 KB Output is correct
41 Correct 83 ms 22004 KB Output is correct
42 Correct 23 ms 12024 KB Output is correct
43 Correct 10 ms 9720 KB Output is correct
44 Correct 10 ms 9720 KB Output is correct
45 Correct 10 ms 9720 KB Output is correct
46 Correct 11 ms 9720 KB Output is correct
47 Correct 11 ms 9720 KB Output is correct
48 Correct 10 ms 9720 KB Output is correct
49 Correct 10 ms 9720 KB Output is correct
50 Correct 11 ms 9744 KB Output is correct
51 Correct 10 ms 9720 KB Output is correct
52 Correct 10 ms 9720 KB Output is correct
53 Correct 11 ms 9812 KB Output is correct
54 Correct 11 ms 9692 KB Output is correct
55 Correct 10 ms 9720 KB Output is correct
56 Correct 10 ms 9720 KB Output is correct
57 Correct 157 ms 21276 KB Output is correct
58 Correct 156 ms 21116 KB Output is correct
59 Correct 168 ms 21496 KB Output is correct
60 Correct 169 ms 21232 KB Output is correct
61 Correct 161 ms 21268 KB Output is correct
62 Correct 164 ms 21352 KB Output is correct
63 Correct 140 ms 21112 KB Output is correct
64 Correct 143 ms 21116 KB Output is correct
65 Correct 141 ms 21368 KB Output is correct
66 Correct 151 ms 21368 KB Output is correct
67 Correct 160 ms 21240 KB Output is correct
68 Correct 184 ms 21404 KB Output is correct
69 Correct 152 ms 21496 KB Output is correct
70 Correct 155 ms 21496 KB Output is correct
71 Correct 10 ms 9720 KB Output is correct
72 Correct 13 ms 10152 KB Output is correct
73 Correct 13 ms 10108 KB Output is correct
74 Correct 13 ms 10104 KB Output is correct
75 Correct 12 ms 10104 KB Output is correct
76 Correct 13 ms 10104 KB Output is correct
77 Correct 13 ms 10092 KB Output is correct
78 Correct 13 ms 10076 KB Output is correct
79 Correct 15 ms 10104 KB Output is correct
80 Correct 169 ms 21240 KB Output is correct
81 Correct 164 ms 21364 KB Output is correct
82 Correct 166 ms 21352 KB Output is correct
83 Correct 154 ms 21248 KB Output is correct
84 Correct 12 ms 9976 KB Output is correct
85 Correct 12 ms 9976 KB Output is correct
86 Correct 12 ms 9976 KB Output is correct
87 Correct 12 ms 9976 KB Output is correct
88 Correct 12 ms 10104 KB Output is correct
89 Correct 13 ms 10044 KB Output is correct
90 Correct 13 ms 9976 KB Output is correct
91 Correct 13 ms 10076 KB Output is correct
92 Correct 13 ms 10104 KB Output is correct
93 Correct 12 ms 10104 KB Output is correct
94 Correct 10 ms 9720 KB Output is correct
95 Correct 10 ms 9720 KB Output is correct
96 Correct 10 ms 9720 KB Output is correct
97 Correct 10 ms 9724 KB Output is correct
98 Correct 10 ms 9748 KB Output is correct
99 Correct 10 ms 9720 KB Output is correct
100 Correct 11 ms 9720 KB Output is correct
101 Correct 10 ms 9692 KB Output is correct
102 Correct 10 ms 9720 KB Output is correct
103 Correct 11 ms 9720 KB Output is correct
104 Correct 23 ms 11256 KB Output is correct
105 Correct 35 ms 13248 KB Output is correct
106 Correct 10 ms 9720 KB Output is correct
107 Correct 62 ms 16472 KB Output is correct
108 Correct 75 ms 19500 KB Output is correct
109 Correct 11 ms 9848 KB Output is correct
110 Correct 106 ms 21648 KB Output is correct
111 Correct 131 ms 23516 KB Output is correct
112 Correct 11 ms 9848 KB Output is correct
113 Correct 194 ms 31668 KB Output is correct
114 Correct 60 ms 15696 KB Output is correct
115 Incorrect 62 ms 15736 KB Output isn't correct
116 Halted 0 ms 0 KB -