답안 #832481

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
832481 2023-08-21T10:47:32 Z MadokaMagicaFan Simurgh (IOI17_simurgh) C++14
51 / 100
78 ms 2444 KB
#include "bits/stdc++.h"
#include "simurgh.h"
using namespace std;
using ll = long long;
#define pb push_back
#define sz(v) ((int)v.size())

int p[500];
int getp(int x) { return p[x] = (x == p[x] ? x : getp(p[x])); }
int uni(int a, int b) {
	a = getp(a);
	b = getp(b);
	if (a == b) return 0;
	p[a] = b;
	return 1;
}

vector<int>
find_roads(int n, vector<int> u, vector<int> v) {
	int m = sz(u);
	vector<int> ans, r, us(m, 0), z;
	for (int i = 0; i < n-1; ++i) {
		for (int i = 0; i < n; ++i) p[i] = i;
		int c = 0;
		if (sz(ans) == n-1) break;
		r = ans;
		for (auto x : ans) {
			c += uni(u[x], v[x]);
		}

		int p = 0;
		while (c < n-2) {
			if (uni(u[p], v[p])) {
				++c;
				r.pb(p);
			}
			++p;
		}

		while (us[p] || getp(u[p]) == getp(v[p]))
			++p;
		r.pb(p);
		z.clear();
		z.pb(p);
		assert(sz(r) == n-1);
		int x = count_common_roads(r);

		for (int j = p+1; j < m; ++j) {
			if(us[j]) continue;
			if (getp(u[j]) == getp(v[j])) continue;
			r[n-2] = j;
			us[j] = 1;
			int l = count_common_roads(r);
			if (l == x) {
				z.pb(j);
			} else if (l < x) {
				break;
			} else if (l > x) {
				z.clear(); z.pb(j);
				break;
			}
		}

		for (auto j : z)
			ans.pb(j);
	}

	return ans;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB correct
2 Correct 0 ms 212 KB correct
3 Correct 0 ms 212 KB correct
4 Correct 0 ms 300 KB correct
5 Correct 0 ms 212 KB correct
6 Correct 0 ms 212 KB correct
7 Correct 0 ms 212 KB correct
8 Correct 0 ms 212 KB correct
9 Correct 1 ms 300 KB correct
10 Correct 1 ms 212 KB correct
11 Correct 0 ms 212 KB correct
12 Correct 0 ms 212 KB correct
13 Correct 0 ms 212 KB correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB correct
2 Correct 0 ms 212 KB correct
3 Correct 0 ms 212 KB correct
4 Correct 0 ms 300 KB correct
5 Correct 0 ms 212 KB correct
6 Correct 0 ms 212 KB correct
7 Correct 0 ms 212 KB correct
8 Correct 0 ms 212 KB correct
9 Correct 1 ms 300 KB correct
10 Correct 1 ms 212 KB correct
11 Correct 0 ms 212 KB correct
12 Correct 0 ms 212 KB correct
13 Correct 0 ms 212 KB correct
14 Correct 2 ms 212 KB correct
15 Correct 1 ms 212 KB correct
16 Correct 1 ms 212 KB correct
17 Correct 1 ms 212 KB correct
18 Correct 1 ms 212 KB correct
19 Correct 1 ms 212 KB correct
20 Correct 1 ms 212 KB correct
21 Correct 1 ms 212 KB correct
22 Correct 1 ms 212 KB correct
23 Correct 1 ms 212 KB correct
24 Correct 1 ms 212 KB correct
25 Correct 1 ms 212 KB correct
26 Correct 1 ms 212 KB correct
27 Correct 1 ms 212 KB correct
28 Correct 1 ms 212 KB correct
29 Correct 1 ms 212 KB correct
30 Correct 1 ms 212 KB correct
31 Correct 1 ms 212 KB correct
32 Correct 1 ms 212 KB correct
33 Correct 1 ms 212 KB correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB correct
2 Correct 0 ms 212 KB correct
3 Correct 0 ms 212 KB correct
4 Correct 0 ms 300 KB correct
5 Correct 0 ms 212 KB correct
6 Correct 0 ms 212 KB correct
7 Correct 0 ms 212 KB correct
8 Correct 0 ms 212 KB correct
9 Correct 1 ms 300 KB correct
10 Correct 1 ms 212 KB correct
11 Correct 0 ms 212 KB correct
12 Correct 0 ms 212 KB correct
13 Correct 0 ms 212 KB correct
14 Correct 2 ms 212 KB correct
15 Correct 1 ms 212 KB correct
16 Correct 1 ms 212 KB correct
17 Correct 1 ms 212 KB correct
18 Correct 1 ms 212 KB correct
19 Correct 1 ms 212 KB correct
20 Correct 1 ms 212 KB correct
21 Correct 1 ms 212 KB correct
22 Correct 1 ms 212 KB correct
23 Correct 1 ms 212 KB correct
24 Correct 1 ms 212 KB correct
25 Correct 1 ms 212 KB correct
26 Correct 1 ms 212 KB correct
27 Correct 1 ms 212 KB correct
28 Correct 1 ms 212 KB correct
29 Correct 1 ms 212 KB correct
30 Correct 1 ms 212 KB correct
31 Correct 1 ms 212 KB correct
32 Correct 1 ms 212 KB correct
33 Correct 1 ms 212 KB correct
34 Correct 67 ms 980 KB correct
35 Correct 68 ms 1044 KB correct
36 Correct 46 ms 816 KB correct
37 Correct 4 ms 340 KB correct
38 Correct 70 ms 964 KB correct
39 Correct 78 ms 944 KB correct
40 Correct 48 ms 812 KB correct
41 Correct 62 ms 980 KB correct
42 Correct 64 ms 1048 KB correct
43 Correct 6 ms 656 KB correct
44 Correct 4 ms 616 KB correct
45 Correct 4 ms 596 KB correct
46 Correct 4 ms 468 KB correct
47 Correct 3 ms 368 KB correct
48 Correct 2 ms 304 KB correct
49 Correct 3 ms 312 KB correct
50 Correct 3 ms 340 KB correct
51 Correct 5 ms 596 KB correct
52 Correct 4 ms 596 KB correct
53 Correct 4 ms 468 KB correct
54 Correct 4 ms 596 KB correct
55 Correct 4 ms 596 KB correct
56 Correct 4 ms 696 KB correct
57 Correct 4 ms 640 KB correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB correct
2 Correct 0 ms 212 KB correct
3 Incorrect 64 ms 2444 KB WA in grader: NO
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB correct
2 Correct 0 ms 212 KB correct
3 Correct 0 ms 212 KB correct
4 Correct 0 ms 300 KB correct
5 Correct 0 ms 212 KB correct
6 Correct 0 ms 212 KB correct
7 Correct 0 ms 212 KB correct
8 Correct 0 ms 212 KB correct
9 Correct 1 ms 300 KB correct
10 Correct 1 ms 212 KB correct
11 Correct 0 ms 212 KB correct
12 Correct 0 ms 212 KB correct
13 Correct 0 ms 212 KB correct
14 Correct 2 ms 212 KB correct
15 Correct 1 ms 212 KB correct
16 Correct 1 ms 212 KB correct
17 Correct 1 ms 212 KB correct
18 Correct 1 ms 212 KB correct
19 Correct 1 ms 212 KB correct
20 Correct 1 ms 212 KB correct
21 Correct 1 ms 212 KB correct
22 Correct 1 ms 212 KB correct
23 Correct 1 ms 212 KB correct
24 Correct 1 ms 212 KB correct
25 Correct 1 ms 212 KB correct
26 Correct 1 ms 212 KB correct
27 Correct 1 ms 212 KB correct
28 Correct 1 ms 212 KB correct
29 Correct 1 ms 212 KB correct
30 Correct 1 ms 212 KB correct
31 Correct 1 ms 212 KB correct
32 Correct 1 ms 212 KB correct
33 Correct 1 ms 212 KB correct
34 Correct 67 ms 980 KB correct
35 Correct 68 ms 1044 KB correct
36 Correct 46 ms 816 KB correct
37 Correct 4 ms 340 KB correct
38 Correct 70 ms 964 KB correct
39 Correct 78 ms 944 KB correct
40 Correct 48 ms 812 KB correct
41 Correct 62 ms 980 KB correct
42 Correct 64 ms 1048 KB correct
43 Correct 6 ms 656 KB correct
44 Correct 4 ms 616 KB correct
45 Correct 4 ms 596 KB correct
46 Correct 4 ms 468 KB correct
47 Correct 3 ms 368 KB correct
48 Correct 2 ms 304 KB correct
49 Correct 3 ms 312 KB correct
50 Correct 3 ms 340 KB correct
51 Correct 5 ms 596 KB correct
52 Correct 4 ms 596 KB correct
53 Correct 4 ms 468 KB correct
54 Correct 4 ms 596 KB correct
55 Correct 4 ms 596 KB correct
56 Correct 4 ms 696 KB correct
57 Correct 4 ms 640 KB correct
58 Correct 0 ms 212 KB correct
59 Correct 0 ms 212 KB correct
60 Incorrect 64 ms 2444 KB WA in grader: NO
61 Halted 0 ms 0 KB -