답안 #466345

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
466345 2021-08-18T19:57:16 Z LucaDantas 통행료 (IOI18_highway) C++17
100 / 100
354 ms 23828 KB
#include "highway.h"
#include <vector>
#include <cstring>
#include <queue>
using namespace std;

#define pb push_back

constexpr int maxn = 90010;

struct Edge { int v, id; };

vector<Edge> g[maxn], tree[maxn][2];
vector<int> ord[2], arv[2];
int pai[maxn];

int dist[maxn][2];
Edge P[maxn][2];
long long SZ; int M, edge;

void bfs(int s, int k) {
	queue<int> q;
	dist[s][k] = 0;
	q.push(s);

	while(q.size()) {
		int u = q.front(); q.pop();
		for(Edge E : g[u]) {
			if(dist[E.v][k] == -1) {
				dist[E.v][k] = dist[u][k] + 1;
				P[E.v][k] = {u, E.id};
				q.push(E.v);
			}
		}
	}
}

void dfs(int u, int k, int p = -1) {
	for(Edge E : tree[u][k]) {
		int v = E.v, id = E.id;
		if(p == v) continue;
		dfs(v, k, u);
		pai[v] = id;
	}
	ord[k].pb(u);
}

int get(int k) {
	int l = 0, r = (int)(ord[k].size()) - 2, ans = ord[k].back();

	while(l <= r) {
		int m = (l+r) >> 1;
		
		vector<int> w(M, 1);
		for(int x : arv[!k])
			w[x] = 0;
		for(int x : arv[k])
			w[x] = 0;
		w[edge] = 0;

		for(int i = 0; i <= m; i++)
			w[pai[ord[k][i]]] = 1;

		long long aq = ask(w);

		if(aq > SZ) ans = ord[k][m], r = m-1;
		else l = m+1;
	}

	return ans;
}

void find_pair(int N, vector<int> U, vector<int> V, int A, int B) {
	M = (int)(U.size());
	vector<int> w(M);
	SZ = ask(w);

	edge = 0; int l = 0, r = M-1;
	while(l <= r) {
		int m = (l+r) >> 1;
		for(int k = 0; k <= m; k++)
			w[k] = 1;
		long long aq = ask(w);
		if(aq > SZ) edge = m, r = m-1;
		else l = m+1;
		for(int& x : w) x = 0;
	}

	for(int i = edge; i < M; i++) {
		g[U[i]].pb({V[i], i});
		g[V[i]].pb({U[i], i});
	}

	memset(dist, -1, sizeof dist);
	bfs(U[edge], 0);
	bfs(V[edge], 1);

	for(int i = 0; i < N; i++) {
		if(dist[i][0] == dist[i][1] || i == U[edge] || i == V[edge]) continue;
		int k = dist[i][1] < dist[i][0];
		tree[i][k].pb(P[i][k]);
		tree[P[i][k].v][k].pb({i, P[i][k].id});
		arv[k].pb(P[i][k].id);
	}

	dfs(U[edge], 0);
	dfs(V[edge], 1);

	answer(get(1), get(0));
}
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 7240 KB Output is correct
2 Correct 4 ms 7240 KB Output is correct
3 Correct 4 ms 7240 KB Output is correct
4 Correct 5 ms 7240 KB Output is correct
5 Correct 4 ms 7240 KB Output is correct
6 Correct 4 ms 7240 KB Output is correct
7 Correct 5 ms 7240 KB Output is correct
8 Correct 5 ms 7240 KB Output is correct
9 Correct 5 ms 7240 KB Output is correct
10 Correct 4 ms 7240 KB Output is correct
11 Correct 4 ms 7272 KB Output is correct
12 Correct 5 ms 7240 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 7496 KB Output is correct
2 Correct 19 ms 8620 KB Output is correct
3 Correct 214 ms 17744 KB Output is correct
4 Correct 217 ms 17612 KB Output is correct
5 Correct 265 ms 18700 KB Output is correct
6 Correct 155 ms 16716 KB Output is correct
7 Correct 160 ms 16328 KB Output is correct
8 Correct 185 ms 18696 KB Output is correct
9 Correct 231 ms 16416 KB Output is correct
10 Correct 164 ms 17464 KB Output is correct
11 Correct 132 ms 15072 KB Output is correct
12 Correct 231 ms 19432 KB Output is correct
13 Correct 257 ms 19288 KB Output is correct
14 Correct 199 ms 19448 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 16 ms 9008 KB Output is correct
2 Correct 38 ms 10608 KB Output is correct
3 Correct 48 ms 8600 KB Output is correct
4 Correct 130 ms 19020 KB Output is correct
5 Correct 144 ms 19260 KB Output is correct
6 Correct 168 ms 21732 KB Output is correct
7 Correct 110 ms 10280 KB Output is correct
8 Correct 114 ms 20348 KB Output is correct
9 Correct 150 ms 13392 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 7368 KB Output is correct
2 Correct 20 ms 8360 KB Output is correct
3 Correct 144 ms 16396 KB Output is correct
4 Correct 154 ms 17604 KB Output is correct
5 Correct 158 ms 14012 KB Output is correct
6 Correct 153 ms 14000 KB Output is correct
7 Correct 154 ms 16432 KB Output is correct
8 Correct 129 ms 14648 KB Output is correct
9 Correct 172 ms 18084 KB Output is correct
10 Correct 180 ms 17200 KB Output is correct
11 Correct 213 ms 18848 KB Output is correct
12 Correct 197 ms 19448 KB Output is correct
13 Correct 212 ms 18404 KB Output is correct
14 Correct 165 ms 15424 KB Output is correct
15 Correct 155 ms 14356 KB Output is correct
16 Correct 138 ms 11804 KB Output is correct
17 Correct 257 ms 18592 KB Output is correct
18 Correct 193 ms 19688 KB Output is correct
19 Correct 105 ms 12704 KB Output is correct
20 Correct 139 ms 14240 KB Output is correct
21 Correct 131 ms 16180 KB Output is correct
22 Correct 152 ms 13392 KB Output is correct
23 Correct 147 ms 19384 KB Output is correct
24 Correct 165 ms 19584 KB Output is correct
25 Correct 238 ms 23828 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 25 ms 8612 KB Output is correct
2 Correct 26 ms 8500 KB Output is correct
3 Correct 267 ms 18820 KB Output is correct
4 Correct 283 ms 18016 KB Output is correct
5 Correct 308 ms 18540 KB Output is correct
6 Correct 288 ms 19596 KB Output is correct
7 Correct 301 ms 18820 KB Output is correct
8 Correct 263 ms 19008 KB Output is correct
9 Correct 191 ms 10924 KB Output is correct
10 Correct 212 ms 13380 KB Output is correct
11 Correct 173 ms 14840 KB Output is correct
12 Correct 234 ms 17964 KB Output is correct
13 Correct 279 ms 18552 KB Output is correct
14 Correct 327 ms 19388 KB Output is correct
15 Correct 296 ms 19592 KB Output is correct
16 Correct 224 ms 15500 KB Output is correct
17 Correct 191 ms 17704 KB Output is correct
18 Correct 115 ms 14500 KB Output is correct
19 Correct 172 ms 18296 KB Output is correct
20 Correct 164 ms 16236 KB Output is correct
21 Correct 271 ms 20712 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 21 ms 8488 KB Output is correct
2 Correct 24 ms 8652 KB Output is correct
3 Correct 214 ms 18652 KB Output is correct
4 Correct 205 ms 18280 KB Output is correct
5 Correct 280 ms 18724 KB Output is correct
6 Correct 300 ms 19252 KB Output is correct
7 Correct 257 ms 19040 KB Output is correct
8 Correct 255 ms 19104 KB Output is correct
9 Correct 220 ms 18560 KB Output is correct
10 Correct 259 ms 19036 KB Output is correct
11 Correct 251 ms 19352 KB Output is correct
12 Correct 321 ms 19096 KB Output is correct
13 Correct 136 ms 11188 KB Output is correct
14 Correct 130 ms 10992 KB Output is correct
15 Correct 239 ms 16492 KB Output is correct
16 Correct 153 ms 13376 KB Output is correct
17 Correct 187 ms 14772 KB Output is correct
18 Correct 191 ms 13516 KB Output is correct
19 Correct 230 ms 17700 KB Output is correct
20 Correct 256 ms 18960 KB Output is correct
21 Correct 319 ms 19412 KB Output is correct
22 Correct 238 ms 19132 KB Output is correct
23 Correct 261 ms 19248 KB Output is correct
24 Correct 305 ms 19340 KB Output is correct
25 Correct 303 ms 19016 KB Output is correct
26 Correct 319 ms 19496 KB Output is correct
27 Correct 132 ms 16084 KB Output is correct
28 Correct 152 ms 17896 KB Output is correct
29 Correct 190 ms 19692 KB Output is correct
30 Correct 181 ms 18860 KB Output is correct
31 Correct 149 ms 18196 KB Output is correct
32 Correct 180 ms 18344 KB Output is correct
33 Correct 190 ms 19652 KB Output is correct
34 Correct 145 ms 17388 KB Output is correct
35 Correct 150 ms 17896 KB Output is correct
36 Correct 201 ms 18728 KB Output is correct
37 Correct 202 ms 18304 KB Output is correct
38 Correct 165 ms 18428 KB Output is correct
39 Correct 328 ms 21128 KB Output is correct
40 Correct 301 ms 21328 KB Output is correct
41 Correct 284 ms 20508 KB Output is correct
42 Correct 354 ms 20560 KB Output is correct