답안 #937662

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
937662 2024-03-04T10:19:39 Z IBory 자매 도시 (APIO20_swap) C++17
37 / 100
2000 ms 14268 KB
#include "swap.h"
#include <bits/stdc++.h>
using namespace std;

const int MAX = 200007;
int N, M, R[MAX], D[MAX];
bool T[MAX], C[MAX], isLine;
vector<tuple<int, int, int>> E;

void Clear() {
	iota(R, R + MAX, 0);
	memset(T, 0, sizeof(T));
	memset(D, 0, sizeof(D));
    memset(C, 0, sizeof(C));
}

void init(int _N, int _M, vector<int> U, vector<int> V, vector<int> W) {
	Clear(); E.clear();
	N = _N, M = _M;
	for (int i = 0; i < M; ++i) {
        E.emplace_back(W[i], U[i], V[i]);
		D[U[i]]++;
		D[V[i]]++;
	}
	if (N == M + 1 && *max_element(D, D + MAX) <= 2) isLine = 1;
	sort(E.begin(), E.end());
}

int Find(int n) {
    T[R[n]] |= T[n];
    C[R[n]] |= C[n];
	if (n == R[n]) return n;
	int r = Find(R[n]);
	return R[n] = r;
}

void Union(int a, int b) {
	if (++D[a] == 3) T[a] = 1;
	if (++D[b] == 3) T[b] = 1;
	a = Find(a), b = Find(b);
	if (a == b) {
        C[a] = 1;
        return;
    }
	R[a] = b;
	T[b] |= T[a];
    C[b] |= C[a];
}

int getMinimumFuelCapacity(int x, int y) {
	if (isLine) return -1;

	int l = -1, r = M - 1;
	while (l + 1 < r) {
		int mid = (l + r) >> 1;

		Clear();
		for (int i = 0; i <= mid; ++i) {
			auto [_, a, b] = E[i];
			Union(a, b);
		}

		bool ok = (Find(x) == Find(y)) && (T[Find(x)] || C[Find(x)]);
		(ok ? r : l) = mid;
	}

	auto [ans, a, b] = E[r];
	return ans;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2140 KB Output is correct
2 Correct 1 ms 2140 KB Output is correct
3 Correct 1 ms 2396 KB Output is correct
4 Correct 1 ms 2396 KB Output is correct
5 Correct 1 ms 2396 KB Output is correct
6 Correct 1 ms 2396 KB Output is correct
7 Correct 1 ms 2396 KB Output is correct
8 Correct 1 ms 2648 KB Output is correct
9 Correct 25 ms 5852 KB Output is correct
10 Correct 30 ms 6304 KB Output is correct
11 Correct 30 ms 6100 KB Output is correct
12 Correct 31 ms 6336 KB Output is correct
13 Correct 31 ms 6280 KB Output is correct
14 Correct 29 ms 5992 KB Output is correct
15 Correct 72 ms 7888 KB Output is correct
16 Correct 71 ms 7624 KB Output is correct
17 Correct 73 ms 7884 KB Output is correct
18 Correct 83 ms 7884 KB Output is correct
19 Execution timed out 2035 ms 4876 KB Time limit exceeded
20 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2140 KB Output is correct
2 Correct 1 ms 2140 KB Output is correct
3 Execution timed out 2063 ms 9512 KB Time limit exceeded
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2140 KB Output is correct
2 Correct 1 ms 2140 KB Output is correct
3 Correct 1 ms 2396 KB Output is correct
4 Correct 1 ms 2396 KB Output is correct
5 Correct 1 ms 2396 KB Output is correct
6 Correct 1 ms 2396 KB Output is correct
7 Correct 1 ms 2396 KB Output is correct
8 Correct 1 ms 2648 KB Output is correct
9 Correct 2 ms 2140 KB Output is correct
10 Correct 9 ms 2408 KB Output is correct
11 Correct 7 ms 2392 KB Output is correct
12 Correct 7 ms 2456 KB Output is correct
13 Correct 8 ms 2396 KB Output is correct
14 Correct 7 ms 2396 KB Output is correct
15 Correct 11 ms 2396 KB Output is correct
16 Correct 11 ms 2396 KB Output is correct
17 Correct 10 ms 2396 KB Output is correct
18 Correct 6 ms 2396 KB Output is correct
19 Correct 5 ms 2396 KB Output is correct
20 Correct 11 ms 2648 KB Output is correct
21 Correct 8 ms 2396 KB Output is correct
22 Correct 8 ms 2516 KB Output is correct
23 Correct 6 ms 2452 KB Output is correct
24 Correct 7 ms 2392 KB Output is correct
25 Correct 9 ms 2396 KB Output is correct
26 Correct 7 ms 2396 KB Output is correct
27 Correct 6 ms 2396 KB Output is correct
28 Correct 7 ms 2300 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 2140 KB Output is correct
2 Correct 1 ms 2140 KB Output is correct
3 Correct 1 ms 2140 KB Output is correct
4 Correct 1 ms 2396 KB Output is correct
5 Correct 1 ms 2396 KB Output is correct
6 Correct 1 ms 2396 KB Output is correct
7 Correct 1 ms 2396 KB Output is correct
8 Correct 1 ms 2396 KB Output is correct
9 Correct 1 ms 2648 KB Output is correct
10 Correct 25 ms 5852 KB Output is correct
11 Correct 30 ms 6304 KB Output is correct
12 Correct 30 ms 6100 KB Output is correct
13 Correct 31 ms 6336 KB Output is correct
14 Correct 31 ms 6280 KB Output is correct
15 Correct 9 ms 2408 KB Output is correct
16 Correct 7 ms 2392 KB Output is correct
17 Correct 7 ms 2456 KB Output is correct
18 Correct 8 ms 2396 KB Output is correct
19 Correct 7 ms 2396 KB Output is correct
20 Correct 11 ms 2396 KB Output is correct
21 Correct 11 ms 2396 KB Output is correct
22 Correct 10 ms 2396 KB Output is correct
23 Correct 6 ms 2396 KB Output is correct
24 Correct 5 ms 2396 KB Output is correct
25 Correct 11 ms 2648 KB Output is correct
26 Correct 8 ms 2396 KB Output is correct
27 Correct 8 ms 2516 KB Output is correct
28 Correct 6 ms 2452 KB Output is correct
29 Correct 7 ms 2392 KB Output is correct
30 Correct 9 ms 2396 KB Output is correct
31 Correct 7 ms 2396 KB Output is correct
32 Correct 6 ms 2396 KB Output is correct
33 Correct 7 ms 2300 KB Output is correct
34 Correct 11 ms 3164 KB Output is correct
35 Correct 264 ms 8132 KB Output is correct
36 Correct 241 ms 8400 KB Output is correct
37 Correct 277 ms 8124 KB Output is correct
38 Correct 275 ms 8136 KB Output is correct
39 Correct 268 ms 8004 KB Output is correct
40 Correct 320 ms 7636 KB Output is correct
41 Correct 257 ms 8292 KB Output is correct
42 Correct 262 ms 8140 KB Output is correct
43 Correct 162 ms 8132 KB Output is correct
44 Correct 320 ms 8404 KB Output is correct
45 Correct 410 ms 12012 KB Output is correct
46 Correct 247 ms 8004 KB Output is correct
47 Correct 264 ms 8004 KB Output is correct
48 Correct 342 ms 8500 KB Output is correct
49 Correct 71 ms 12740 KB Output is correct
50 Correct 74 ms 9020 KB Output is correct
51 Correct 233 ms 9672 KB Output is correct
52 Correct 361 ms 13456 KB Output is correct
53 Correct 270 ms 14268 KB Output is correct
54 Correct 303 ms 14164 KB Output is correct
55 Correct 197 ms 8124 KB Output is correct
56 Correct 570 ms 13172 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2140 KB Output is correct
2 Correct 1 ms 2140 KB Output is correct
3 Correct 1 ms 2396 KB Output is correct
4 Correct 1 ms 2396 KB Output is correct
5 Correct 1 ms 2396 KB Output is correct
6 Correct 1 ms 2396 KB Output is correct
7 Correct 1 ms 2396 KB Output is correct
8 Correct 1 ms 2648 KB Output is correct
9 Correct 25 ms 5852 KB Output is correct
10 Correct 30 ms 6304 KB Output is correct
11 Correct 30 ms 6100 KB Output is correct
12 Correct 31 ms 6336 KB Output is correct
13 Correct 31 ms 6280 KB Output is correct
14 Correct 29 ms 5992 KB Output is correct
15 Correct 72 ms 7888 KB Output is correct
16 Correct 71 ms 7624 KB Output is correct
17 Correct 73 ms 7884 KB Output is correct
18 Correct 83 ms 7884 KB Output is correct
19 Execution timed out 2063 ms 9512 KB Time limit exceeded
20 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 2140 KB Output is correct
2 Correct 1 ms 2140 KB Output is correct
3 Correct 1 ms 2140 KB Output is correct
4 Correct 1 ms 2396 KB Output is correct
5 Correct 1 ms 2396 KB Output is correct
6 Correct 1 ms 2396 KB Output is correct
7 Correct 1 ms 2396 KB Output is correct
8 Correct 1 ms 2396 KB Output is correct
9 Correct 1 ms 2648 KB Output is correct
10 Correct 25 ms 5852 KB Output is correct
11 Correct 30 ms 6304 KB Output is correct
12 Correct 30 ms 6100 KB Output is correct
13 Correct 31 ms 6336 KB Output is correct
14 Correct 31 ms 6280 KB Output is correct
15 Correct 29 ms 5992 KB Output is correct
16 Correct 72 ms 7888 KB Output is correct
17 Correct 71 ms 7624 KB Output is correct
18 Correct 73 ms 7884 KB Output is correct
19 Correct 83 ms 7884 KB Output is correct
20 Execution timed out 2063 ms 9512 KB Time limit exceeded
21 Halted 0 ms 0 KB -