답안 #72264

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
72264 2018-08-26T06:31:43 Z nvmdava 꿈 (IOI13_dreaming) C++17
47 / 100
291 ms 34164 KB
#include "dreaming.h"
#include <bits/stdc++.h>
using namespace std;

struct Path{
	int to, cost;
	Path(int _to, int _cost){
		to = _to;
		cost = _cost;
	}
};

struct Node{
	int p[20], d;
};
map<int, int> c[100001];
vector<Path> path[100001];
bool in[100001];
Node a[100001];
int mxdist, mxid;
int lol = 0;
void build(int v, int p){
	in[v] = 1;
	for(auto x : path[v]){
		if(x.to == p) continue;
		a[x.to].d = a[v].d + 1;
		memset(a[x.to].p, -1, sizeof(a[x.to].p));
		a[x.to].p[0] = v;
		for(int i = 1; i < 20; i++){
			int t = a[x.to].p[i - 1];
			if(t == -1) break;
			a[x.to].p[i] = a[t].p[i - 1];
		}
		build(x.to, v);
	}
}

int goUp(int v, int u){
	for(int i = 0; i < 20; i++){
		if(u & (1 << i)) v = a[v].p[i];
	}
	return v;
}

int lca(int v, int u){
	int l = 0;
	int r = min(a[v].d, a[u].d) + 1;
	int m;
	while(l + 1 != r){
		m = (l + r) >> 1;
		if(goUp(v, a[v].d - m) == goUp(u, a[u].d - m)) l = m;
		else r = m;
	}
	return goUp(v, a[v].d - l);
}

void dfs(int v, int p, int d){
	if(path[v].size() == 1 && p != -1){
		if(d > mxdist){
			mxdist = d;
			mxid = v;
		}
	}
	for(auto x : path[v]){
		if(x.to == p) continue;
		dfs(x.to, v, d + x.cost);
	}
}

int comp = 0;

int go(int v){
	if(in[v]) return 0;
	comp++;
	if(path[v].size() == 0) return 0;
	memset(a[v].p, -1, sizeof(a[v].p));
	a[v].d = 0;
	build(v, -1);
	
	mxdist = 0;
	mxid = v;
	dfs(v, -1, 0);
	mxdist = 0;
	v = mxid;
	dfs(v, -1, 0);
	int u = mxid;
	int o = lca(v, u);
	lol = max(lol, mxdist);
	int s = (mxdist + 1) >> 1;
	int q = 0;
	while(v != o){
		q += c[v][a[v].p[0]];
		if(q >= s){
			return min(q, mxdist - q + c[v][a[v].p[0]]);
		}
		v = a[v].p[0];
	}
	q = 0;
	while(u != o){
		q += c[u][a[u].p[0]];
		if(q >= s){
//			cout<<min(q, mxdist - q + c[u][a[u].p[0]])<<"\n";
			return min(q, mxdist - q + c[u][a[u].p[0]]);
		}
		u = a[u].p[0];
	}
}

int travelTime(int N, int M, int L, int A[], int B[], int T[]) {
    
    for(int i = 0; i < M; i++){
    	path[A[i]].push_back(Path(B[i], T[i]));
    	path[B[i]].push_back(Path(A[i], T[i]));
    	c[A[i]][B[i]] = T[i];
    	c[B[i]][A[i]] = T[i];
	}
	int mx = 0;
	int mx2 = 0;
	int s;
	for(int i = 0; i < N; i++){
		s = go(i);
		if(s > mx){
			mx2 = mx;
			mx = s;
		} else if(s > mx2) mx2 = s;
	}
	if(comp == 1) return lol;
	return max(L + mx + mx2, lol);
}

Compilation message

dreaming.cpp: In function 'int go(int)':
dreaming.cpp:107:1: warning: control reaches end of non-void function [-Wreturn-type]
 }
 ^
# 결과 실행 시간 메모리 Grader output
1 Correct 188 ms 31860 KB Output is correct
2 Correct 161 ms 31816 KB Output is correct
3 Correct 114 ms 23524 KB Output is correct
4 Correct 20 ms 11000 KB Output is correct
5 Correct 18 ms 9856 KB Output is correct
6 Correct 31 ms 12664 KB Output is correct
7 Correct 8 ms 7396 KB Output is correct
8 Correct 67 ms 17400 KB Output is correct
9 Correct 88 ms 20344 KB Output is correct
10 Correct 7 ms 7552 KB Output is correct
11 Correct 143 ms 24960 KB Output is correct
12 Correct 171 ms 28280 KB Output is correct
13 Correct 8 ms 7552 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 188 ms 31860 KB Output is correct
2 Correct 161 ms 31816 KB Output is correct
3 Correct 114 ms 23524 KB Output is correct
4 Correct 20 ms 11000 KB Output is correct
5 Correct 18 ms 9856 KB Output is correct
6 Correct 31 ms 12664 KB Output is correct
7 Correct 8 ms 7396 KB Output is correct
8 Correct 67 ms 17400 KB Output is correct
9 Correct 88 ms 20344 KB Output is correct
10 Correct 7 ms 7552 KB Output is correct
11 Correct 143 ms 24960 KB Output is correct
12 Correct 171 ms 28280 KB Output is correct
13 Correct 8 ms 7552 KB Output is correct
14 Correct 7 ms 7424 KB Output is correct
15 Correct 7 ms 7424 KB Output is correct
16 Correct 8 ms 7424 KB Output is correct
17 Correct 7 ms 7424 KB Output is correct
18 Correct 8 ms 7424 KB Output is correct
19 Correct 7 ms 7424 KB Output is correct
20 Correct 8 ms 7424 KB Output is correct
21 Correct 9 ms 7552 KB Output is correct
22 Correct 7 ms 7424 KB Output is correct
23 Correct 8 ms 7424 KB Output is correct
24 Correct 7 ms 7424 KB Output is correct
25 Correct 7 ms 7424 KB Output is correct
26 Correct 7 ms 7424 KB Output is correct
27 Correct 7 ms 7424 KB Output is correct
28 Correct 7 ms 7424 KB Output is correct
29 Correct 7 ms 7424 KB Output is correct
30 Correct 8 ms 7424 KB Output is correct
31 Correct 8 ms 7424 KB Output is correct
32 Correct 7 ms 7424 KB Output is correct
33 Correct 8 ms 7424 KB Output is correct
34 Correct 8 ms 7424 KB Output is correct
35 Correct 7 ms 7424 KB Output is correct
36 Correct 7 ms 7424 KB Output is correct
37 Correct 8 ms 7424 KB Output is correct
38 Correct 9 ms 7424 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 188 ms 31860 KB Output is correct
2 Correct 161 ms 31816 KB Output is correct
3 Correct 114 ms 23524 KB Output is correct
4 Correct 20 ms 11000 KB Output is correct
5 Correct 18 ms 9856 KB Output is correct
6 Correct 31 ms 12664 KB Output is correct
7 Correct 8 ms 7396 KB Output is correct
8 Correct 67 ms 17400 KB Output is correct
9 Correct 88 ms 20344 KB Output is correct
10 Correct 7 ms 7552 KB Output is correct
11 Correct 143 ms 24960 KB Output is correct
12 Correct 171 ms 28280 KB Output is correct
13 Correct 8 ms 7552 KB Output is correct
14 Correct 7 ms 7424 KB Output is correct
15 Correct 7 ms 7424 KB Output is correct
16 Correct 8 ms 7424 KB Output is correct
17 Correct 7 ms 7424 KB Output is correct
18 Correct 8 ms 7424 KB Output is correct
19 Correct 7 ms 7424 KB Output is correct
20 Correct 8 ms 7424 KB Output is correct
21 Correct 9 ms 7552 KB Output is correct
22 Correct 7 ms 7424 KB Output is correct
23 Correct 8 ms 7424 KB Output is correct
24 Correct 7 ms 7424 KB Output is correct
25 Correct 7 ms 7424 KB Output is correct
26 Correct 7 ms 7424 KB Output is correct
27 Correct 7 ms 7424 KB Output is correct
28 Correct 7 ms 7424 KB Output is correct
29 Correct 7 ms 7424 KB Output is correct
30 Correct 8 ms 7424 KB Output is correct
31 Correct 8 ms 7424 KB Output is correct
32 Correct 7 ms 7424 KB Output is correct
33 Correct 8 ms 7424 KB Output is correct
34 Correct 8 ms 7424 KB Output is correct
35 Correct 7 ms 7424 KB Output is correct
36 Correct 7 ms 7424 KB Output is correct
37 Correct 8 ms 7424 KB Output is correct
38 Correct 9 ms 7424 KB Output is correct
39 Correct 169 ms 31660 KB Output is correct
40 Correct 160 ms 31736 KB Output is correct
41 Correct 100 ms 23388 KB Output is correct
42 Correct 21 ms 11008 KB Output is correct
43 Correct 8 ms 7424 KB Output is correct
44 Correct 11 ms 7424 KB Output is correct
45 Correct 7 ms 7424 KB Output is correct
46 Correct 7 ms 7424 KB Output is correct
47 Correct 7 ms 7424 KB Output is correct
48 Correct 8 ms 7424 KB Output is correct
49 Correct 8 ms 7424 KB Output is correct
50 Correct 9 ms 7424 KB Output is correct
51 Correct 7 ms 7424 KB Output is correct
52 Correct 8 ms 7424 KB Output is correct
53 Correct 7 ms 7424 KB Output is correct
54 Correct 7 ms 7424 KB Output is correct
55 Correct 8 ms 7424 KB Output is correct
56 Correct 7 ms 7424 KB Output is correct
57 Correct 209 ms 30304 KB Output is correct
58 Correct 214 ms 30332 KB Output is correct
59 Correct 233 ms 30160 KB Output is correct
60 Correct 233 ms 30332 KB Output is correct
61 Correct 208 ms 30200 KB Output is correct
62 Correct 194 ms 30072 KB Output is correct
63 Correct 205 ms 29944 KB Output is correct
64 Correct 204 ms 30072 KB Output is correct
65 Correct 291 ms 29916 KB Output is correct
66 Correct 216 ms 29944 KB Output is correct
67 Correct 229 ms 30328 KB Output is correct
68 Correct 212 ms 30200 KB Output is correct
69 Correct 238 ms 30312 KB Output is correct
70 Correct 238 ms 30348 KB Output is correct
71 Correct 7 ms 7552 KB Output is correct
72 Correct 10 ms 8064 KB Output is correct
73 Correct 10 ms 8064 KB Output is correct
74 Correct 10 ms 8064 KB Output is correct
75 Correct 10 ms 8064 KB Output is correct
76 Correct 10 ms 8064 KB Output is correct
77 Correct 10 ms 8064 KB Output is correct
78 Correct 10 ms 8064 KB Output is correct
79 Correct 10 ms 8064 KB Output is correct
80 Correct 213 ms 30200 KB Output is correct
81 Correct 214 ms 30200 KB Output is correct
82 Correct 202 ms 30072 KB Output is correct
83 Correct 211 ms 30224 KB Output is correct
84 Correct 10 ms 7968 KB Output is correct
85 Correct 10 ms 7808 KB Output is correct
86 Correct 9 ms 7936 KB Output is correct
87 Correct 10 ms 8064 KB Output is correct
88 Correct 10 ms 8064 KB Output is correct
89 Correct 10 ms 8064 KB Output is correct
90 Correct 10 ms 7908 KB Output is correct
91 Correct 10 ms 8064 KB Output is correct
92 Correct 11 ms 8064 KB Output is correct
93 Correct 11 ms 8064 KB Output is correct
94 Correct 7 ms 7424 KB Output is correct
95 Correct 8 ms 7424 KB Output is correct
96 Correct 8 ms 7424 KB Output is correct
97 Correct 7 ms 7424 KB Output is correct
98 Correct 7 ms 7424 KB Output is correct
99 Correct 8 ms 7424 KB Output is correct
100 Correct 8 ms 7424 KB Output is correct
101 Correct 8 ms 7424 KB Output is correct
102 Correct 7 ms 7424 KB Output is correct
103 Correct 7 ms 7424 KB Output is correct
104 Correct 17 ms 9856 KB Output is correct
105 Correct 33 ms 12792 KB Output is correct
106 Correct 7 ms 7424 KB Output is correct
107 Correct 80 ms 17372 KB Output is correct
108 Correct 99 ms 20344 KB Output is correct
109 Correct 8 ms 7552 KB Output is correct
110 Correct 157 ms 25056 KB Output is correct
111 Correct 192 ms 28280 KB Output is correct
112 Correct 8 ms 7548 KB Output is correct
113 Correct 256 ms 34164 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 59 ms 20460 KB Output is correct
2 Incorrect 75 ms 20472 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 188 ms 31860 KB Output is correct
2 Correct 161 ms 31816 KB Output is correct
3 Correct 114 ms 23524 KB Output is correct
4 Correct 20 ms 11000 KB Output is correct
5 Correct 18 ms 9856 KB Output is correct
6 Correct 31 ms 12664 KB Output is correct
7 Correct 8 ms 7396 KB Output is correct
8 Correct 67 ms 17400 KB Output is correct
9 Correct 88 ms 20344 KB Output is correct
10 Correct 7 ms 7552 KB Output is correct
11 Correct 143 ms 24960 KB Output is correct
12 Correct 171 ms 28280 KB Output is correct
13 Correct 8 ms 7552 KB Output is correct
14 Correct 9 ms 7552 KB Output is correct
15 Correct 9 ms 7808 KB Output is correct
16 Correct 10 ms 8064 KB Output is correct
17 Correct 8 ms 7552 KB Output is correct
18 Correct 9 ms 7808 KB Output is correct
19 Correct 10 ms 8064 KB Output is correct
20 Incorrect 9 ms 7552 KB Output isn't correct
21 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 188 ms 31860 KB Output is correct
2 Correct 161 ms 31816 KB Output is correct
3 Correct 114 ms 23524 KB Output is correct
4 Correct 20 ms 11000 KB Output is correct
5 Correct 18 ms 9856 KB Output is correct
6 Correct 31 ms 12664 KB Output is correct
7 Correct 8 ms 7396 KB Output is correct
8 Correct 67 ms 17400 KB Output is correct
9 Correct 88 ms 20344 KB Output is correct
10 Correct 7 ms 7552 KB Output is correct
11 Correct 143 ms 24960 KB Output is correct
12 Correct 171 ms 28280 KB Output is correct
13 Correct 8 ms 7552 KB Output is correct
14 Correct 7 ms 7424 KB Output is correct
15 Correct 7 ms 7424 KB Output is correct
16 Correct 8 ms 7424 KB Output is correct
17 Correct 7 ms 7424 KB Output is correct
18 Correct 8 ms 7424 KB Output is correct
19 Correct 7 ms 7424 KB Output is correct
20 Correct 8 ms 7424 KB Output is correct
21 Correct 9 ms 7552 KB Output is correct
22 Correct 7 ms 7424 KB Output is correct
23 Correct 8 ms 7424 KB Output is correct
24 Correct 7 ms 7424 KB Output is correct
25 Correct 7 ms 7424 KB Output is correct
26 Correct 7 ms 7424 KB Output is correct
27 Correct 7 ms 7424 KB Output is correct
28 Correct 7 ms 7424 KB Output is correct
29 Correct 7 ms 7424 KB Output is correct
30 Correct 8 ms 7424 KB Output is correct
31 Correct 8 ms 7424 KB Output is correct
32 Correct 7 ms 7424 KB Output is correct
33 Correct 8 ms 7424 KB Output is correct
34 Correct 8 ms 7424 KB Output is correct
35 Correct 7 ms 7424 KB Output is correct
36 Correct 7 ms 7424 KB Output is correct
37 Correct 8 ms 7424 KB Output is correct
38 Correct 9 ms 7424 KB Output is correct
39 Correct 169 ms 31660 KB Output is correct
40 Correct 160 ms 31736 KB Output is correct
41 Correct 100 ms 23388 KB Output is correct
42 Correct 21 ms 11008 KB Output is correct
43 Correct 8 ms 7424 KB Output is correct
44 Correct 11 ms 7424 KB Output is correct
45 Correct 7 ms 7424 KB Output is correct
46 Correct 7 ms 7424 KB Output is correct
47 Correct 7 ms 7424 KB Output is correct
48 Correct 8 ms 7424 KB Output is correct
49 Correct 8 ms 7424 KB Output is correct
50 Correct 9 ms 7424 KB Output is correct
51 Correct 7 ms 7424 KB Output is correct
52 Correct 8 ms 7424 KB Output is correct
53 Correct 7 ms 7424 KB Output is correct
54 Correct 7 ms 7424 KB Output is correct
55 Correct 8 ms 7424 KB Output is correct
56 Correct 7 ms 7424 KB Output is correct
57 Correct 209 ms 30304 KB Output is correct
58 Correct 214 ms 30332 KB Output is correct
59 Correct 233 ms 30160 KB Output is correct
60 Correct 233 ms 30332 KB Output is correct
61 Correct 208 ms 30200 KB Output is correct
62 Correct 194 ms 30072 KB Output is correct
63 Correct 205 ms 29944 KB Output is correct
64 Correct 204 ms 30072 KB Output is correct
65 Correct 291 ms 29916 KB Output is correct
66 Correct 216 ms 29944 KB Output is correct
67 Correct 229 ms 30328 KB Output is correct
68 Correct 212 ms 30200 KB Output is correct
69 Correct 238 ms 30312 KB Output is correct
70 Correct 238 ms 30348 KB Output is correct
71 Correct 7 ms 7552 KB Output is correct
72 Correct 10 ms 8064 KB Output is correct
73 Correct 10 ms 8064 KB Output is correct
74 Correct 10 ms 8064 KB Output is correct
75 Correct 10 ms 8064 KB Output is correct
76 Correct 10 ms 8064 KB Output is correct
77 Correct 10 ms 8064 KB Output is correct
78 Correct 10 ms 8064 KB Output is correct
79 Correct 10 ms 8064 KB Output is correct
80 Correct 213 ms 30200 KB Output is correct
81 Correct 214 ms 30200 KB Output is correct
82 Correct 202 ms 30072 KB Output is correct
83 Correct 211 ms 30224 KB Output is correct
84 Correct 10 ms 7968 KB Output is correct
85 Correct 10 ms 7808 KB Output is correct
86 Correct 9 ms 7936 KB Output is correct
87 Correct 10 ms 8064 KB Output is correct
88 Correct 10 ms 8064 KB Output is correct
89 Correct 10 ms 8064 KB Output is correct
90 Correct 10 ms 7908 KB Output is correct
91 Correct 10 ms 8064 KB Output is correct
92 Correct 11 ms 8064 KB Output is correct
93 Correct 11 ms 8064 KB Output is correct
94 Correct 7 ms 7424 KB Output is correct
95 Correct 8 ms 7424 KB Output is correct
96 Correct 8 ms 7424 KB Output is correct
97 Correct 7 ms 7424 KB Output is correct
98 Correct 7 ms 7424 KB Output is correct
99 Correct 8 ms 7424 KB Output is correct
100 Correct 8 ms 7424 KB Output is correct
101 Correct 8 ms 7424 KB Output is correct
102 Correct 7 ms 7424 KB Output is correct
103 Correct 7 ms 7424 KB Output is correct
104 Correct 17 ms 9856 KB Output is correct
105 Correct 33 ms 12792 KB Output is correct
106 Correct 7 ms 7424 KB Output is correct
107 Correct 80 ms 17372 KB Output is correct
108 Correct 99 ms 20344 KB Output is correct
109 Correct 8 ms 7552 KB Output is correct
110 Correct 157 ms 25056 KB Output is correct
111 Correct 192 ms 28280 KB Output is correct
112 Correct 8 ms 7548 KB Output is correct
113 Correct 256 ms 34164 KB Output is correct
114 Correct 59 ms 20460 KB Output is correct
115 Incorrect 75 ms 20472 KB Output isn't correct
116 Halted 0 ms 0 KB -