답안 #393202

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
393202 2021-04-22T23:56:27 Z abdzag 슈퍼트리 잇기 (IOI20_supertrees) C++17
75 / 100
281 ms 22212 KB
#include<bits/stdc++.h>
#include"supertrees.h"
#define rep(i,a,b) for(int i=a;i<int(b);i++)
#define rrep(i,a,b)for(int i=a;i>int(b);i--)
#define all(v) v.begin(),v.end()
#define trav(a,v) for(auto& a: v)
typedef long long ll;
using namespace std;
const long long inf = 1e15;

vector<ll> p(2001);
vector<ll> Rank(2001);
ll Ufindset(ll i) {
	if (p[i] == i)return i;
	return p[i] = Ufindset(p[i]);
}
void UjoinSet(ll i, ll j) {
	ll si = Ufindset(i);
	ll sj = Ufindset(j);
	if (sj == si)return;
	if (Rank[sj] > Rank[si])swap(sj, si);
	p[sj] = si;
	if (Rank[sj] == Rank[si]) Rank[si]++;
}
void print(vector<ll> v) {
	trav(a, v)cout << a << " ";
	cout << endl;
}
int construct(vector<vector<int>> v) {
	rep(i, 0, 2001)p[i] = i;
	vector<vector<int>> b(v.size(), vector<int>(v.size()));
	rep(i, 0, v.size()) {
		ll root = p[i];
		ll last = i;
		ll two = 0;
		rep(j, 0, v.size()) {
			if (v[i][j] == 3)return 0;
			if (v[i][j]) {
				if (v[i][j] == 2) {
					p[p[i]] = i;
					p[i] = i;
					two++;
				}
				else if (v[i][j] == 1)UjoinSet(i, j);
			}
		}
	}

	rep(i, 0, v.size()) Ufindset(i);
	rep(i, 0, v.size()) {
		ll last = i;
		rep(j, 0, v.size()) {
			if (i == j)continue;
			if (v[i][j]) {
				if (v[i][j] == 1) {
					if (p[i] == i) {
						UjoinSet(last, j);
						b[last][j] = 1;
						b[j][last] = 1;
					}
					last = j;
				}
			}
		}
	}

	rep(i, 0, v.size()) {
		ll last = i;
		ll two = 0;
		rep(j, 0, v.size()) {
			Ufindset(j);
			if (i == j)continue;
			if (v[i][j]) {
				if (p[j] != j) {
					if (p[j] != p[i]) {
						if (v[i][p[i]] == 1) {
							if (v[p[j]][j] == 1) {
								if (v[p[i]][p[j]] == 1) {
									if (v[i][j] != 1)return 0;
								}
								else if (v[p[i]][p[j]] == 2) {
									if (v[i][j] != 2)return 0;
								}
								else if (v[i][j]) return 0;
							}
							else {
								if (v[p[i]][p[j]] == 1) {
									if (v[i][j] != 2)return 0;
								}
								else if (v[p[i]][p[j]] == 2) {
									return 0;
								}
								else if (v[i][j]) return 0;
							}
						}
						else {
							if (v[p[j]][j] == 1) {
								if (v[p[i]][p[j]] == 1) {
									if (v[i][j] != 2)return 0;
								}
								else if (v[p[i]][p[j]] == 2) {
									return 0;
								}
								else if (v[i][j]) return 0;
							}
							else {
								if (v[j][i])return 0;
							}
						}
					}
				}
			}
			else {
				if (v[p[j]][p[i]]) return 0;
			}
			if (p[i] == i) {
				if (p[j] == j) {
					if (v[i][j] == 2) {
						two++;

						UjoinSet(last, j);
						b[last][j] = 1;
						b[j][last] = 1;
						last = j;
					}
				}


			}
		}
		if (p[i] == i && two) {
			if (two == 1)return 0;
			if (p[i] == i) {
				UjoinSet(last, i);
				b[last][i] = 1;
				b[i][last] = 1;
			}
		}
	}
	build(b);
	return 1;
}

Compilation message

supertrees.cpp: In function 'int construct(std::vector<std::vector<int> >)':
supertrees.cpp:33:6: warning: unused variable 'root' [-Wunused-variable]
   33 |   ll root = p[i];
      |      ^~~~
supertrees.cpp:34:6: warning: unused variable 'last' [-Wunused-variable]
   34 |   ll last = i;
      |      ^~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 11 ms 1100 KB Output is correct
7 Correct 266 ms 21948 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 11 ms 1100 KB Output is correct
7 Correct 266 ms 21948 KB Output is correct
8 Correct 1 ms 204 KB Output is correct
9 Correct 1 ms 204 KB Output is correct
10 Correct 1 ms 204 KB Output is correct
11 Correct 1 ms 332 KB Output is correct
12 Correct 11 ms 1100 KB Output is correct
13 Correct 250 ms 22080 KB Output is correct
14 Correct 1 ms 332 KB Output is correct
15 Correct 1 ms 204 KB Output is correct
16 Correct 5 ms 716 KB Output is correct
17 Correct 125 ms 12060 KB Output is correct
18 Correct 1 ms 332 KB Output is correct
19 Correct 1 ms 204 KB Output is correct
20 Correct 66 ms 5792 KB Output is correct
21 Correct 256 ms 21956 KB Output is correct
22 Correct 258 ms 22212 KB Output is correct
23 Correct 276 ms 22064 KB Output is correct
24 Correct 252 ms 21956 KB Output is correct
25 Correct 105 ms 12076 KB Output is correct
26 Correct 105 ms 12100 KB Output is correct
27 Correct 271 ms 22044 KB Output is correct
28 Correct 248 ms 21956 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 11 ms 1100 KB Output is correct
9 Correct 249 ms 22044 KB Output is correct
10 Correct 1 ms 204 KB Output is correct
11 Correct 1 ms 204 KB Output is correct
12 Correct 11 ms 1120 KB Output is correct
13 Correct 257 ms 22052 KB Output is correct
14 Correct 1 ms 204 KB Output is correct
15 Correct 1 ms 332 KB Output is correct
16 Correct 5 ms 716 KB Output is correct
17 Correct 115 ms 12076 KB Output is correct
18 Correct 1 ms 204 KB Output is correct
19 Correct 1 ms 204 KB Output is correct
20 Correct 1 ms 204 KB Output is correct
21 Correct 63 ms 5792 KB Output is correct
22 Correct 259 ms 22124 KB Output is correct
23 Correct 249 ms 22060 KB Output is correct
24 Correct 264 ms 21956 KB Output is correct
25 Correct 104 ms 12064 KB Output is correct
26 Correct 104 ms 12080 KB Output is correct
27 Correct 253 ms 22060 KB Output is correct
28 Correct 265 ms 21956 KB Output is correct
29 Correct 104 ms 12200 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 64 ms 5852 KB Output is correct
5 Correct 259 ms 21956 KB Output is correct
6 Correct 256 ms 22060 KB Output is correct
7 Correct 281 ms 22060 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 66 ms 5700 KB Output is correct
10 Correct 262 ms 22084 KB Output is correct
11 Correct 258 ms 21956 KB Output is correct
12 Correct 265 ms 21960 KB Output is correct
13 Correct 1 ms 204 KB Output is correct
14 Correct 1 ms 204 KB Output is correct
15 Correct 1 ms 204 KB Output is correct
16 Correct 64 ms 5828 KB Output is correct
17 Correct 252 ms 22064 KB Output is correct
18 Correct 255 ms 22176 KB Output is correct
19 Correct 256 ms 21956 KB Output is correct
20 Correct 273 ms 22048 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 11 ms 1100 KB Output is correct
7 Correct 266 ms 21948 KB Output is correct
8 Correct 1 ms 204 KB Output is correct
9 Correct 1 ms 204 KB Output is correct
10 Correct 1 ms 204 KB Output is correct
11 Correct 1 ms 332 KB Output is correct
12 Correct 11 ms 1100 KB Output is correct
13 Correct 250 ms 22080 KB Output is correct
14 Correct 1 ms 332 KB Output is correct
15 Correct 1 ms 204 KB Output is correct
16 Correct 5 ms 716 KB Output is correct
17 Correct 125 ms 12060 KB Output is correct
18 Correct 1 ms 332 KB Output is correct
19 Correct 1 ms 204 KB Output is correct
20 Correct 66 ms 5792 KB Output is correct
21 Correct 256 ms 21956 KB Output is correct
22 Correct 258 ms 22212 KB Output is correct
23 Correct 276 ms 22064 KB Output is correct
24 Correct 252 ms 21956 KB Output is correct
25 Correct 105 ms 12076 KB Output is correct
26 Correct 105 ms 12100 KB Output is correct
27 Correct 271 ms 22044 KB Output is correct
28 Correct 248 ms 21956 KB Output is correct
29 Correct 1 ms 332 KB Output is correct
30 Correct 1 ms 204 KB Output is correct
31 Correct 1 ms 332 KB Output is correct
32 Correct 1 ms 204 KB Output is correct
33 Correct 1 ms 204 KB Output is correct
34 Correct 1 ms 204 KB Output is correct
35 Correct 1 ms 204 KB Output is correct
36 Correct 11 ms 1100 KB Output is correct
37 Correct 249 ms 22044 KB Output is correct
38 Correct 1 ms 204 KB Output is correct
39 Correct 1 ms 204 KB Output is correct
40 Correct 11 ms 1120 KB Output is correct
41 Correct 257 ms 22052 KB Output is correct
42 Correct 1 ms 204 KB Output is correct
43 Correct 1 ms 332 KB Output is correct
44 Correct 5 ms 716 KB Output is correct
45 Correct 115 ms 12076 KB Output is correct
46 Correct 1 ms 204 KB Output is correct
47 Correct 1 ms 204 KB Output is correct
48 Correct 1 ms 204 KB Output is correct
49 Correct 63 ms 5792 KB Output is correct
50 Correct 259 ms 22124 KB Output is correct
51 Correct 249 ms 22060 KB Output is correct
52 Correct 264 ms 21956 KB Output is correct
53 Correct 104 ms 12064 KB Output is correct
54 Correct 104 ms 12080 KB Output is correct
55 Correct 253 ms 22060 KB Output is correct
56 Correct 265 ms 21956 KB Output is correct
57 Correct 104 ms 12200 KB Output is correct
58 Correct 1 ms 204 KB Output is correct
59 Correct 1 ms 332 KB Output is correct
60 Correct 5 ms 748 KB Output is correct
61 Correct 123 ms 12064 KB Output is correct
62 Correct 1 ms 204 KB Output is correct
63 Correct 1 ms 204 KB Output is correct
64 Correct 1 ms 204 KB Output is correct
65 Incorrect 26 ms 3236 KB Answer gives possible 0 while actual possible 1
66 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 11 ms 1100 KB Output is correct
7 Correct 266 ms 21948 KB Output is correct
8 Correct 1 ms 204 KB Output is correct
9 Correct 1 ms 204 KB Output is correct
10 Correct 1 ms 204 KB Output is correct
11 Correct 1 ms 332 KB Output is correct
12 Correct 11 ms 1100 KB Output is correct
13 Correct 250 ms 22080 KB Output is correct
14 Correct 1 ms 332 KB Output is correct
15 Correct 1 ms 204 KB Output is correct
16 Correct 5 ms 716 KB Output is correct
17 Correct 125 ms 12060 KB Output is correct
18 Correct 1 ms 332 KB Output is correct
19 Correct 1 ms 204 KB Output is correct
20 Correct 66 ms 5792 KB Output is correct
21 Correct 256 ms 21956 KB Output is correct
22 Correct 258 ms 22212 KB Output is correct
23 Correct 276 ms 22064 KB Output is correct
24 Correct 252 ms 21956 KB Output is correct
25 Correct 105 ms 12076 KB Output is correct
26 Correct 105 ms 12100 KB Output is correct
27 Correct 271 ms 22044 KB Output is correct
28 Correct 248 ms 21956 KB Output is correct
29 Correct 1 ms 332 KB Output is correct
30 Correct 1 ms 204 KB Output is correct
31 Correct 1 ms 332 KB Output is correct
32 Correct 1 ms 204 KB Output is correct
33 Correct 1 ms 204 KB Output is correct
34 Correct 1 ms 204 KB Output is correct
35 Correct 1 ms 204 KB Output is correct
36 Correct 11 ms 1100 KB Output is correct
37 Correct 249 ms 22044 KB Output is correct
38 Correct 1 ms 204 KB Output is correct
39 Correct 1 ms 204 KB Output is correct
40 Correct 11 ms 1120 KB Output is correct
41 Correct 257 ms 22052 KB Output is correct
42 Correct 1 ms 204 KB Output is correct
43 Correct 1 ms 332 KB Output is correct
44 Correct 5 ms 716 KB Output is correct
45 Correct 115 ms 12076 KB Output is correct
46 Correct 1 ms 204 KB Output is correct
47 Correct 1 ms 204 KB Output is correct
48 Correct 1 ms 204 KB Output is correct
49 Correct 63 ms 5792 KB Output is correct
50 Correct 259 ms 22124 KB Output is correct
51 Correct 249 ms 22060 KB Output is correct
52 Correct 264 ms 21956 KB Output is correct
53 Correct 104 ms 12064 KB Output is correct
54 Correct 104 ms 12080 KB Output is correct
55 Correct 253 ms 22060 KB Output is correct
56 Correct 265 ms 21956 KB Output is correct
57 Correct 104 ms 12200 KB Output is correct
58 Correct 1 ms 332 KB Output is correct
59 Correct 1 ms 332 KB Output is correct
60 Correct 1 ms 204 KB Output is correct
61 Correct 64 ms 5852 KB Output is correct
62 Correct 259 ms 21956 KB Output is correct
63 Correct 256 ms 22060 KB Output is correct
64 Correct 281 ms 22060 KB Output is correct
65 Correct 1 ms 332 KB Output is correct
66 Correct 66 ms 5700 KB Output is correct
67 Correct 262 ms 22084 KB Output is correct
68 Correct 258 ms 21956 KB Output is correct
69 Correct 265 ms 21960 KB Output is correct
70 Correct 1 ms 204 KB Output is correct
71 Correct 1 ms 204 KB Output is correct
72 Correct 1 ms 204 KB Output is correct
73 Correct 64 ms 5828 KB Output is correct
74 Correct 252 ms 22064 KB Output is correct
75 Correct 255 ms 22176 KB Output is correct
76 Correct 256 ms 21956 KB Output is correct
77 Correct 273 ms 22048 KB Output is correct
78 Correct 1 ms 204 KB Output is correct
79 Correct 1 ms 332 KB Output is correct
80 Correct 5 ms 748 KB Output is correct
81 Correct 123 ms 12064 KB Output is correct
82 Correct 1 ms 204 KB Output is correct
83 Correct 1 ms 204 KB Output is correct
84 Correct 1 ms 204 KB Output is correct
85 Incorrect 26 ms 3236 KB Answer gives possible 0 while actual possible 1
86 Halted 0 ms 0 KB -