답안 #297856

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
297856 2020-09-12T05:23:09 Z tmwilliamlin168 자매 도시 (APIO20_swap) C++14
100 / 100
557 ms 41792 KB
#include "swap.h"
#include <bits/stdc++.h>
using namespace std;

#define ar array

const int mxN=1e5;
int n, a[mxN], r[mxN];

struct tree {
	int d[mxN], anc[mxN][17], b1[mxN][17];
	vector<ar<int, 2>> adj[mxN];
	vector<int> adj2[mxN];
	int find(int x) {
		return x^r[x]?r[x]=find(r[x]):x;
	}
	void dfs2(int u, int w) {
		a[u]=min(w, a[u]);
		for(int v : adj2[u])
			dfs2(v, w);
		adj2[u].clear();
	}
	bool join(int x, int y, int w) {
		if((x=find(x))==(y=find(y)))
			return 0;
		r[x]=y;
		if(a[y]<=1e9)
			dfs2(x, w);
		if(a[x]<=1e9)
			dfs2(y, w);
		adj2[y].push_back(x);
		return 1;
	}
	void co(vector<ar<int, 3>> e) {
		iota(r, r+n, 0);
		for(auto f : e) {
			if(join(f[1], f[2], f[0])) {
				adj[f[1]].push_back({f[0], f[2]});
				adj[f[2]].push_back({f[0], f[1]});
				if(adj[f[1]].size()>2||adj[f[2]].size()>2)
					dfs2(find(f[1]), f[0]);
			} else
				dfs2(find(f[1]), f[0]);
		}
	}
	void dfs(int u=0, int p=-1) {
		anc[u][0]=p;
		for(int i=1; i<17; ++i) {
			anc[u][i]=~anc[u][i-1]?anc[anc[u][i-1]][i-1]:-1;
			b1[u][i]=~anc[u][i-1]?max(b1[u][i-1], b1[anc[u][i-1]][i-1]):0;
		}
		for(auto v : adj[u]) {
			if(v[1]^p) {
				b1[v[1]][0]=v[0];
				d[v[1]]=d[u]+1;
				dfs(v[1], u);
			}
		}
	}
	int qry(int x, int y) {
		if(d[x]<d[y])
			swap(x, y);
		int r=0;
		for(int i=16; ~i; --i) {
			if(d[x]-(1<<i)>=d[y]) {
				r=max(b1[x][i], r);
				x=anc[x][i];
			}
		}
		if(x==y)
			return r;
		for(int i=16; ~i; --i) {
			if(anc[x][i]^anc[y][i]) {
				r=max({b1[x][i], b1[y][i], r});
				x=anc[x][i];
				y=anc[y][i];
			}
		}
		return max({b1[x][0], b1[y][0], r});
	}
} t0;

void init(int n, int m, vector<int> u, vector<int> v, vector<int> w) {
	::n=n;
	vector<ar<int, 3>> e;
	for(int i=0; i<m; ++i)
		e.push_back({w[i], u[i], v[i]});
	sort(e.begin(), e.end());
	memset(a, 0x3f, 4*n);
	t0.co(e);
	t0.dfs();
}

int getMinimumFuelCapacity(int x, int y) {
	int b=max(t0.qry(x, y), a[x]);
	return b>1e9?-1:b;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 4992 KB Output is correct
2 Correct 4 ms 4992 KB Output is correct
3 Correct 5 ms 4992 KB Output is correct
4 Correct 4 ms 5120 KB Output is correct
5 Correct 5 ms 5376 KB Output is correct
6 Correct 5 ms 5248 KB Output is correct
7 Correct 5 ms 5376 KB Output is correct
8 Correct 5 ms 5376 KB Output is correct
9 Correct 160 ms 27604 KB Output is correct
10 Correct 208 ms 33668 KB Output is correct
11 Correct 195 ms 32936 KB Output is correct
12 Correct 207 ms 34648 KB Output is correct
13 Correct 182 ms 36056 KB Output is correct
14 Correct 184 ms 27348 KB Output is correct
15 Correct 457 ms 37500 KB Output is correct
16 Correct 469 ms 35356 KB Output is correct
17 Correct 439 ms 39896 KB Output is correct
18 Correct 423 ms 38872 KB Output is correct
19 Correct 120 ms 14908 KB Output is correct
20 Correct 480 ms 37108 KB Output is correct
21 Correct 477 ms 35864 KB Output is correct
22 Correct 484 ms 38564 KB Output is correct
23 Correct 461 ms 38916 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 4992 KB Output is correct
2 Correct 4 ms 4992 KB Output is correct
3 Correct 262 ms 34448 KB Output is correct
4 Correct 277 ms 35660 KB Output is correct
5 Correct 270 ms 35252 KB Output is correct
6 Correct 268 ms 35504 KB Output is correct
7 Correct 275 ms 35452 KB Output is correct
8 Correct 259 ms 34448 KB Output is correct
9 Correct 268 ms 35192 KB Output is correct
10 Correct 257 ms 34212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 4992 KB Output is correct
2 Correct 4 ms 4992 KB Output is correct
3 Correct 4 ms 4992 KB Output is correct
4 Correct 5 ms 4992 KB Output is correct
5 Correct 4 ms 5120 KB Output is correct
6 Correct 5 ms 5376 KB Output is correct
7 Correct 5 ms 5248 KB Output is correct
8 Correct 5 ms 5376 KB Output is correct
9 Correct 5 ms 5376 KB Output is correct
10 Correct 5 ms 5248 KB Output is correct
11 Correct 5 ms 5376 KB Output is correct
12 Correct 5 ms 5248 KB Output is correct
13 Correct 4 ms 5248 KB Output is correct
14 Correct 5 ms 5248 KB Output is correct
15 Correct 5 ms 5248 KB Output is correct
16 Correct 5 ms 5376 KB Output is correct
17 Correct 5 ms 5376 KB Output is correct
18 Correct 5 ms 5248 KB Output is correct
19 Correct 5 ms 5248 KB Output is correct
20 Correct 4 ms 5376 KB Output is correct
21 Correct 4 ms 5248 KB Output is correct
22 Correct 5 ms 5248 KB Output is correct
23 Correct 4 ms 5248 KB Output is correct
24 Correct 5 ms 5376 KB Output is correct
25 Correct 5 ms 5376 KB Output is correct
26 Correct 5 ms 5376 KB Output is correct
27 Correct 5 ms 5376 KB Output is correct
28 Correct 5 ms 5504 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 4992 KB Output is correct
2 Correct 4 ms 4992 KB Output is correct
3 Correct 4 ms 4992 KB Output is correct
4 Correct 5 ms 4992 KB Output is correct
5 Correct 4 ms 5120 KB Output is correct
6 Correct 5 ms 5376 KB Output is correct
7 Correct 5 ms 5248 KB Output is correct
8 Correct 5 ms 5376 KB Output is correct
9 Correct 5 ms 5376 KB Output is correct
10 Correct 160 ms 27604 KB Output is correct
11 Correct 208 ms 33668 KB Output is correct
12 Correct 195 ms 32936 KB Output is correct
13 Correct 207 ms 34648 KB Output is correct
14 Correct 182 ms 36056 KB Output is correct
15 Correct 5 ms 5248 KB Output is correct
16 Correct 5 ms 5376 KB Output is correct
17 Correct 5 ms 5248 KB Output is correct
18 Correct 4 ms 5248 KB Output is correct
19 Correct 5 ms 5248 KB Output is correct
20 Correct 5 ms 5248 KB Output is correct
21 Correct 5 ms 5376 KB Output is correct
22 Correct 5 ms 5376 KB Output is correct
23 Correct 5 ms 5248 KB Output is correct
24 Correct 19 ms 8480 KB Output is correct
25 Correct 214 ms 33912 KB Output is correct
26 Correct 206 ms 31980 KB Output is correct
27 Correct 194 ms 30296 KB Output is correct
28 Correct 191 ms 29672 KB Output is correct
29 Correct 188 ms 29260 KB Output is correct
30 Correct 168 ms 27448 KB Output is correct
31 Correct 217 ms 32728 KB Output is correct
32 Correct 214 ms 33372 KB Output is correct
33 Correct 177 ms 34392 KB Output is correct
34 Correct 185 ms 30300 KB Output is correct
35 Correct 5 ms 5248 KB Output is correct
36 Correct 4 ms 5376 KB Output is correct
37 Correct 4 ms 5248 KB Output is correct
38 Correct 5 ms 5248 KB Output is correct
39 Correct 4 ms 5248 KB Output is correct
40 Correct 5 ms 5376 KB Output is correct
41 Correct 5 ms 5376 KB Output is correct
42 Correct 5 ms 5376 KB Output is correct
43 Correct 5 ms 5376 KB Output is correct
44 Correct 5 ms 5504 KB Output is correct
45 Correct 187 ms 28828 KB Output is correct
46 Correct 207 ms 31044 KB Output is correct
47 Correct 189 ms 29652 KB Output is correct
48 Correct 185 ms 29900 KB Output is correct
49 Correct 93 ms 15336 KB Output is correct
50 Correct 78 ms 13420 KB Output is correct
51 Correct 144 ms 24844 KB Output is correct
52 Correct 258 ms 34948 KB Output is correct
53 Correct 249 ms 35392 KB Output is correct
54 Correct 269 ms 38080 KB Output is correct
55 Correct 177 ms 35412 KB Output is correct
56 Correct 230 ms 34444 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 4992 KB Output is correct
2 Correct 4 ms 4992 KB Output is correct
3 Correct 5 ms 4992 KB Output is correct
4 Correct 4 ms 5120 KB Output is correct
5 Correct 5 ms 5376 KB Output is correct
6 Correct 5 ms 5248 KB Output is correct
7 Correct 5 ms 5376 KB Output is correct
8 Correct 5 ms 5376 KB Output is correct
9 Correct 160 ms 27604 KB Output is correct
10 Correct 208 ms 33668 KB Output is correct
11 Correct 195 ms 32936 KB Output is correct
12 Correct 207 ms 34648 KB Output is correct
13 Correct 182 ms 36056 KB Output is correct
14 Correct 184 ms 27348 KB Output is correct
15 Correct 457 ms 37500 KB Output is correct
16 Correct 469 ms 35356 KB Output is correct
17 Correct 439 ms 39896 KB Output is correct
18 Correct 423 ms 38872 KB Output is correct
19 Correct 262 ms 34448 KB Output is correct
20 Correct 277 ms 35660 KB Output is correct
21 Correct 270 ms 35252 KB Output is correct
22 Correct 268 ms 35504 KB Output is correct
23 Correct 275 ms 35452 KB Output is correct
24 Correct 259 ms 34448 KB Output is correct
25 Correct 268 ms 35192 KB Output is correct
26 Correct 257 ms 34212 KB Output is correct
27 Correct 5 ms 5248 KB Output is correct
28 Correct 5 ms 5376 KB Output is correct
29 Correct 5 ms 5248 KB Output is correct
30 Correct 4 ms 5248 KB Output is correct
31 Correct 5 ms 5248 KB Output is correct
32 Correct 5 ms 5248 KB Output is correct
33 Correct 5 ms 5376 KB Output is correct
34 Correct 5 ms 5376 KB Output is correct
35 Correct 5 ms 5248 KB Output is correct
36 Correct 19 ms 8480 KB Output is correct
37 Correct 214 ms 33912 KB Output is correct
38 Correct 206 ms 31980 KB Output is correct
39 Correct 194 ms 30296 KB Output is correct
40 Correct 191 ms 29672 KB Output is correct
41 Correct 188 ms 29260 KB Output is correct
42 Correct 168 ms 27448 KB Output is correct
43 Correct 217 ms 32728 KB Output is correct
44 Correct 214 ms 33372 KB Output is correct
45 Correct 177 ms 34392 KB Output is correct
46 Correct 185 ms 30300 KB Output is correct
47 Correct 29 ms 8600 KB Output is correct
48 Correct 505 ms 36328 KB Output is correct
49 Correct 498 ms 35160 KB Output is correct
50 Correct 456 ms 34264 KB Output is correct
51 Correct 441 ms 33860 KB Output is correct
52 Correct 390 ms 32132 KB Output is correct
53 Correct 279 ms 26824 KB Output is correct
54 Correct 498 ms 36648 KB Output is correct
55 Correct 485 ms 36900 KB Output is correct
56 Correct 437 ms 38744 KB Output is correct
57 Correct 377 ms 34760 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 4992 KB Output is correct
2 Correct 4 ms 4992 KB Output is correct
3 Correct 4 ms 4992 KB Output is correct
4 Correct 5 ms 4992 KB Output is correct
5 Correct 4 ms 5120 KB Output is correct
6 Correct 5 ms 5376 KB Output is correct
7 Correct 5 ms 5248 KB Output is correct
8 Correct 5 ms 5376 KB Output is correct
9 Correct 5 ms 5376 KB Output is correct
10 Correct 160 ms 27604 KB Output is correct
11 Correct 208 ms 33668 KB Output is correct
12 Correct 195 ms 32936 KB Output is correct
13 Correct 207 ms 34648 KB Output is correct
14 Correct 182 ms 36056 KB Output is correct
15 Correct 184 ms 27348 KB Output is correct
16 Correct 457 ms 37500 KB Output is correct
17 Correct 469 ms 35356 KB Output is correct
18 Correct 439 ms 39896 KB Output is correct
19 Correct 423 ms 38872 KB Output is correct
20 Correct 262 ms 34448 KB Output is correct
21 Correct 277 ms 35660 KB Output is correct
22 Correct 270 ms 35252 KB Output is correct
23 Correct 268 ms 35504 KB Output is correct
24 Correct 275 ms 35452 KB Output is correct
25 Correct 259 ms 34448 KB Output is correct
26 Correct 268 ms 35192 KB Output is correct
27 Correct 257 ms 34212 KB Output is correct
28 Correct 5 ms 5248 KB Output is correct
29 Correct 5 ms 5376 KB Output is correct
30 Correct 5 ms 5248 KB Output is correct
31 Correct 4 ms 5248 KB Output is correct
32 Correct 5 ms 5248 KB Output is correct
33 Correct 5 ms 5248 KB Output is correct
34 Correct 5 ms 5376 KB Output is correct
35 Correct 5 ms 5376 KB Output is correct
36 Correct 5 ms 5248 KB Output is correct
37 Correct 19 ms 8480 KB Output is correct
38 Correct 214 ms 33912 KB Output is correct
39 Correct 206 ms 31980 KB Output is correct
40 Correct 194 ms 30296 KB Output is correct
41 Correct 191 ms 29672 KB Output is correct
42 Correct 188 ms 29260 KB Output is correct
43 Correct 168 ms 27448 KB Output is correct
44 Correct 217 ms 32728 KB Output is correct
45 Correct 214 ms 33372 KB Output is correct
46 Correct 177 ms 34392 KB Output is correct
47 Correct 185 ms 30300 KB Output is correct
48 Correct 29 ms 8600 KB Output is correct
49 Correct 505 ms 36328 KB Output is correct
50 Correct 498 ms 35160 KB Output is correct
51 Correct 456 ms 34264 KB Output is correct
52 Correct 441 ms 33860 KB Output is correct
53 Correct 390 ms 32132 KB Output is correct
54 Correct 279 ms 26824 KB Output is correct
55 Correct 498 ms 36648 KB Output is correct
56 Correct 485 ms 36900 KB Output is correct
57 Correct 437 ms 38744 KB Output is correct
58 Correct 377 ms 34760 KB Output is correct
59 Correct 120 ms 14908 KB Output is correct
60 Correct 480 ms 37108 KB Output is correct
61 Correct 477 ms 35864 KB Output is correct
62 Correct 484 ms 38564 KB Output is correct
63 Correct 461 ms 38916 KB Output is correct
64 Correct 5 ms 5248 KB Output is correct
65 Correct 4 ms 5376 KB Output is correct
66 Correct 4 ms 5248 KB Output is correct
67 Correct 5 ms 5248 KB Output is correct
68 Correct 4 ms 5248 KB Output is correct
69 Correct 5 ms 5376 KB Output is correct
70 Correct 5 ms 5376 KB Output is correct
71 Correct 5 ms 5376 KB Output is correct
72 Correct 5 ms 5376 KB Output is correct
73 Correct 5 ms 5504 KB Output is correct
74 Correct 187 ms 28828 KB Output is correct
75 Correct 207 ms 31044 KB Output is correct
76 Correct 189 ms 29652 KB Output is correct
77 Correct 185 ms 29900 KB Output is correct
78 Correct 93 ms 15336 KB Output is correct
79 Correct 78 ms 13420 KB Output is correct
80 Correct 144 ms 24844 KB Output is correct
81 Correct 258 ms 34948 KB Output is correct
82 Correct 249 ms 35392 KB Output is correct
83 Correct 269 ms 38080 KB Output is correct
84 Correct 177 ms 35412 KB Output is correct
85 Correct 230 ms 34444 KB Output is correct
86 Correct 92 ms 14884 KB Output is correct
87 Correct 497 ms 34900 KB Output is correct
88 Correct 475 ms 34904 KB Output is correct
89 Correct 329 ms 32396 KB Output is correct
90 Correct 204 ms 19304 KB Output is correct
91 Correct 215 ms 19176 KB Output is correct
92 Correct 305 ms 28372 KB Output is correct
93 Correct 506 ms 38940 KB Output is correct
94 Correct 424 ms 39116 KB Output is correct
95 Correct 557 ms 41792 KB Output is correct
96 Correct 447 ms 37076 KB Output is correct
97 Correct 388 ms 36404 KB Output is correct