답안 #301617

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
301617 2020-09-18T05:25:25 Z Namnamseo 슈퍼트리 잇기 (IOI20_supertrees) C++17
100 / 100
271 ms 22280 KB
#include "supertrees.h"
#include <vector>
#include <numeric>
using namespace std;
#define rep(i, n) for(int i=0; i<n; ++i)
#define pb push_back

int n;

namespace unf {
	int par[1010];
	void init() {
		iota(par, par+n, 0);
	}
	int r(int x) { return (x==par[x]) ? x : (par[x]=r(par[x])); }
	void join(int a, int b) {
		a = r(a); b = r(b);
		if (a == b) return;
		par[a] = b;
	}
	bool same(int a, int b) { return r(a) == r(b); }
};
using namespace unf;

vector<int> g[1010];

int ans[1010][1010];
vector<int> go[1010];
int work(int gi, auto &p) {
	auto &v = g[gi];

	if (v.size() == 1u) return 1;

	for(int x:v) par[x] = x;
	vector<int> v1;
	for(int x:v) {
		bool ok = 0;
		for(int y:v) if (p[x][y] == 1 && x != y) join(x, y), ok = 1;
		if (ok) v1.pb(x);
	}

	for(int x:v1) go[r(x)].pb(x);
	for(int x:v1) if (par[x] == x) {
		auto &t = go[x];
		int gs = t.size();
		for(int i=0; i+1<gs; ++i) {
			ans[t[i]][t[i+1]] = 1;
			ans[t[i+1]][t[i]] = 1;
		}
		for(int a:t) for(int b:t) if (p[a][b] != 1) return 0;
	}

	for(int x:v) for(int y:v) {
		if ((r(x)==r(y)) != (p[x][y] == 1)) return 0;
	}

	vector<int> cyc;
	for(int x:v) if (par[x] == x) cyc.pb(x);
	for(int i=0, s=cyc.size(); i<s-1; ++i) ans[cyc[i]][cyc[i+1]] = ans[cyc[i+1]][cyc[i]] = 1;
	if (cyc.size() == 2u) return 0;
	if (cyc.size() >= 2u) ans[cyc[0]][cyc.back()] = ans[cyc.back()][cyc[0]] = 1;

	return 1;
}

int construct(vector<vector<int>> p) {
	n = p.size();

	unf::init();

	rep(i, n) rep(j, n) if (p[i][j]) { if (p[i][j] == 3) return 0; join(i, j); }
	rep(i, n) rep(j, n) if (same(i, j) != !!p[i][j]) return 0;

	rep(i, n) g[r(i)].pb(i);

	rep(i, n) if (par[i] == i) if (!work(i, p)) return 0;

	rep(i, n) rep(j, n) p[i][j] = ans[i][j];
	build(p);

	return 1;
}

Compilation message

supertrees.cpp:29:18: warning: use of 'auto' in parameter declaration only available with '-fconcepts'
   29 | int work(int gi, auto &p) {
      |                  ^~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 0 ms 384 KB Output is correct
3 Correct 0 ms 384 KB Output is correct
4 Correct 0 ms 384 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Correct 11 ms 1920 KB Output is correct
7 Correct 262 ms 22264 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 0 ms 384 KB Output is correct
3 Correct 0 ms 384 KB Output is correct
4 Correct 0 ms 384 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Correct 11 ms 1920 KB Output is correct
7 Correct 262 ms 22264 KB Output is correct
8 Correct 0 ms 384 KB Output is correct
9 Correct 0 ms 384 KB Output is correct
10 Correct 0 ms 384 KB Output is correct
11 Correct 0 ms 384 KB Output is correct
12 Correct 10 ms 1152 KB Output is correct
13 Correct 238 ms 18168 KB Output is correct
14 Correct 0 ms 384 KB Output is correct
15 Correct 0 ms 384 KB Output is correct
16 Correct 5 ms 640 KB Output is correct
17 Correct 113 ms 8204 KB Output is correct
18 Correct 1 ms 384 KB Output is correct
19 Correct 0 ms 384 KB Output is correct
20 Correct 61 ms 6776 KB Output is correct
21 Correct 244 ms 22136 KB Output is correct
22 Correct 243 ms 21752 KB Output is correct
23 Correct 271 ms 22280 KB Output is correct
24 Correct 241 ms 18424 KB Output is correct
25 Correct 101 ms 8312 KB Output is correct
26 Correct 102 ms 8184 KB Output is correct
27 Correct 263 ms 22136 KB Output is correct
28 Correct 237 ms 18424 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 384 KB Output is correct
2 Correct 0 ms 384 KB Output is correct
3 Correct 0 ms 384 KB Output is correct
4 Correct 0 ms 384 KB Output is correct
5 Correct 0 ms 384 KB Output is correct
6 Correct 1 ms 384 KB Output is correct
7 Correct 0 ms 384 KB Output is correct
8 Correct 12 ms 1152 KB Output is correct
9 Correct 239 ms 18168 KB Output is correct
10 Correct 1 ms 384 KB Output is correct
11 Correct 0 ms 384 KB Output is correct
12 Correct 11 ms 1920 KB Output is correct
13 Correct 248 ms 22136 KB Output is correct
14 Correct 0 ms 384 KB Output is correct
15 Correct 0 ms 384 KB Output is correct
16 Correct 5 ms 640 KB Output is correct
17 Correct 114 ms 8196 KB Output is correct
18 Correct 0 ms 384 KB Output is correct
19 Correct 0 ms 384 KB Output is correct
20 Correct 0 ms 384 KB Output is correct
21 Correct 63 ms 6648 KB Output is correct
22 Correct 243 ms 22136 KB Output is correct
23 Correct 239 ms 22136 KB Output is correct
24 Correct 259 ms 22136 KB Output is correct
25 Correct 105 ms 8440 KB Output is correct
26 Correct 105 ms 8184 KB Output is correct
27 Correct 243 ms 22136 KB Output is correct
28 Correct 266 ms 22264 KB Output is correct
29 Correct 104 ms 8332 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 384 KB Output is correct
2 Correct 0 ms 512 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 62 ms 6648 KB Output is correct
5 Correct 261 ms 22156 KB Output is correct
6 Correct 240 ms 21752 KB Output is correct
7 Correct 262 ms 22264 KB Output is correct
8 Correct 0 ms 384 KB Output is correct
9 Correct 63 ms 6736 KB Output is correct
10 Correct 245 ms 22248 KB Output is correct
11 Correct 238 ms 22136 KB Output is correct
12 Correct 259 ms 22264 KB Output is correct
13 Correct 1 ms 384 KB Output is correct
14 Correct 0 ms 384 KB Output is correct
15 Correct 0 ms 384 KB Output is correct
16 Correct 61 ms 6776 KB Output is correct
17 Correct 253 ms 22136 KB Output is correct
18 Correct 242 ms 22136 KB Output is correct
19 Correct 246 ms 22136 KB Output is correct
20 Correct 234 ms 18520 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 0 ms 384 KB Output is correct
3 Correct 0 ms 384 KB Output is correct
4 Correct 0 ms 384 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Correct 11 ms 1920 KB Output is correct
7 Correct 262 ms 22264 KB Output is correct
8 Correct 0 ms 384 KB Output is correct
9 Correct 0 ms 384 KB Output is correct
10 Correct 0 ms 384 KB Output is correct
11 Correct 0 ms 384 KB Output is correct
12 Correct 10 ms 1152 KB Output is correct
13 Correct 238 ms 18168 KB Output is correct
14 Correct 0 ms 384 KB Output is correct
15 Correct 0 ms 384 KB Output is correct
16 Correct 5 ms 640 KB Output is correct
17 Correct 113 ms 8204 KB Output is correct
18 Correct 1 ms 384 KB Output is correct
19 Correct 0 ms 384 KB Output is correct
20 Correct 61 ms 6776 KB Output is correct
21 Correct 244 ms 22136 KB Output is correct
22 Correct 243 ms 21752 KB Output is correct
23 Correct 271 ms 22280 KB Output is correct
24 Correct 241 ms 18424 KB Output is correct
25 Correct 101 ms 8312 KB Output is correct
26 Correct 102 ms 8184 KB Output is correct
27 Correct 263 ms 22136 KB Output is correct
28 Correct 237 ms 18424 KB Output is correct
29 Correct 0 ms 384 KB Output is correct
30 Correct 0 ms 384 KB Output is correct
31 Correct 0 ms 384 KB Output is correct
32 Correct 0 ms 384 KB Output is correct
33 Correct 0 ms 384 KB Output is correct
34 Correct 1 ms 384 KB Output is correct
35 Correct 0 ms 384 KB Output is correct
36 Correct 12 ms 1152 KB Output is correct
37 Correct 239 ms 18168 KB Output is correct
38 Correct 1 ms 384 KB Output is correct
39 Correct 0 ms 384 KB Output is correct
40 Correct 11 ms 1920 KB Output is correct
41 Correct 248 ms 22136 KB Output is correct
42 Correct 0 ms 384 KB Output is correct
43 Correct 0 ms 384 KB Output is correct
44 Correct 5 ms 640 KB Output is correct
45 Correct 114 ms 8196 KB Output is correct
46 Correct 0 ms 384 KB Output is correct
47 Correct 0 ms 384 KB Output is correct
48 Correct 0 ms 384 KB Output is correct
49 Correct 63 ms 6648 KB Output is correct
50 Correct 243 ms 22136 KB Output is correct
51 Correct 239 ms 22136 KB Output is correct
52 Correct 259 ms 22136 KB Output is correct
53 Correct 105 ms 8440 KB Output is correct
54 Correct 105 ms 8184 KB Output is correct
55 Correct 243 ms 22136 KB Output is correct
56 Correct 266 ms 22264 KB Output is correct
57 Correct 104 ms 8332 KB Output is correct
58 Correct 0 ms 384 KB Output is correct
59 Correct 0 ms 384 KB Output is correct
60 Correct 5 ms 640 KB Output is correct
61 Correct 112 ms 8312 KB Output is correct
62 Correct 0 ms 384 KB Output is correct
63 Correct 1 ms 384 KB Output is correct
64 Correct 0 ms 384 KB Output is correct
65 Correct 62 ms 6648 KB Output is correct
66 Correct 103 ms 8184 KB Output is correct
67 Correct 103 ms 8184 KB Output is correct
68 Correct 97 ms 8204 KB Output is correct
69 Correct 101 ms 8312 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 0 ms 384 KB Output is correct
3 Correct 0 ms 384 KB Output is correct
4 Correct 0 ms 384 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Correct 11 ms 1920 KB Output is correct
7 Correct 262 ms 22264 KB Output is correct
8 Correct 0 ms 384 KB Output is correct
9 Correct 0 ms 384 KB Output is correct
10 Correct 0 ms 384 KB Output is correct
11 Correct 0 ms 384 KB Output is correct
12 Correct 10 ms 1152 KB Output is correct
13 Correct 238 ms 18168 KB Output is correct
14 Correct 0 ms 384 KB Output is correct
15 Correct 0 ms 384 KB Output is correct
16 Correct 5 ms 640 KB Output is correct
17 Correct 113 ms 8204 KB Output is correct
18 Correct 1 ms 384 KB Output is correct
19 Correct 0 ms 384 KB Output is correct
20 Correct 61 ms 6776 KB Output is correct
21 Correct 244 ms 22136 KB Output is correct
22 Correct 243 ms 21752 KB Output is correct
23 Correct 271 ms 22280 KB Output is correct
24 Correct 241 ms 18424 KB Output is correct
25 Correct 101 ms 8312 KB Output is correct
26 Correct 102 ms 8184 KB Output is correct
27 Correct 263 ms 22136 KB Output is correct
28 Correct 237 ms 18424 KB Output is correct
29 Correct 0 ms 384 KB Output is correct
30 Correct 0 ms 384 KB Output is correct
31 Correct 0 ms 384 KB Output is correct
32 Correct 0 ms 384 KB Output is correct
33 Correct 0 ms 384 KB Output is correct
34 Correct 1 ms 384 KB Output is correct
35 Correct 0 ms 384 KB Output is correct
36 Correct 12 ms 1152 KB Output is correct
37 Correct 239 ms 18168 KB Output is correct
38 Correct 1 ms 384 KB Output is correct
39 Correct 0 ms 384 KB Output is correct
40 Correct 11 ms 1920 KB Output is correct
41 Correct 248 ms 22136 KB Output is correct
42 Correct 0 ms 384 KB Output is correct
43 Correct 0 ms 384 KB Output is correct
44 Correct 5 ms 640 KB Output is correct
45 Correct 114 ms 8196 KB Output is correct
46 Correct 0 ms 384 KB Output is correct
47 Correct 0 ms 384 KB Output is correct
48 Correct 0 ms 384 KB Output is correct
49 Correct 63 ms 6648 KB Output is correct
50 Correct 243 ms 22136 KB Output is correct
51 Correct 239 ms 22136 KB Output is correct
52 Correct 259 ms 22136 KB Output is correct
53 Correct 105 ms 8440 KB Output is correct
54 Correct 105 ms 8184 KB Output is correct
55 Correct 243 ms 22136 KB Output is correct
56 Correct 266 ms 22264 KB Output is correct
57 Correct 104 ms 8332 KB Output is correct
58 Correct 0 ms 384 KB Output is correct
59 Correct 0 ms 512 KB Output is correct
60 Correct 1 ms 384 KB Output is correct
61 Correct 62 ms 6648 KB Output is correct
62 Correct 261 ms 22156 KB Output is correct
63 Correct 240 ms 21752 KB Output is correct
64 Correct 262 ms 22264 KB Output is correct
65 Correct 0 ms 384 KB Output is correct
66 Correct 63 ms 6736 KB Output is correct
67 Correct 245 ms 22248 KB Output is correct
68 Correct 238 ms 22136 KB Output is correct
69 Correct 259 ms 22264 KB Output is correct
70 Correct 1 ms 384 KB Output is correct
71 Correct 0 ms 384 KB Output is correct
72 Correct 0 ms 384 KB Output is correct
73 Correct 61 ms 6776 KB Output is correct
74 Correct 253 ms 22136 KB Output is correct
75 Correct 242 ms 22136 KB Output is correct
76 Correct 246 ms 22136 KB Output is correct
77 Correct 234 ms 18520 KB Output is correct
78 Correct 0 ms 384 KB Output is correct
79 Correct 0 ms 384 KB Output is correct
80 Correct 5 ms 640 KB Output is correct
81 Correct 112 ms 8312 KB Output is correct
82 Correct 0 ms 384 KB Output is correct
83 Correct 1 ms 384 KB Output is correct
84 Correct 0 ms 384 KB Output is correct
85 Correct 62 ms 6648 KB Output is correct
86 Correct 103 ms 8184 KB Output is correct
87 Correct 103 ms 8184 KB Output is correct
88 Correct 97 ms 8204 KB Output is correct
89 Correct 101 ms 8312 KB Output is correct
90 Correct 0 ms 384 KB Output is correct
91 Correct 0 ms 384 KB Output is correct
92 Correct 5 ms 640 KB Output is correct
93 Correct 102 ms 8312 KB Output is correct
94 Correct 0 ms 384 KB Output is correct
95 Correct 0 ms 384 KB Output is correct
96 Correct 1 ms 384 KB Output is correct
97 Correct 24 ms 2304 KB Output is correct
98 Correct 102 ms 8184 KB Output is correct
99 Correct 102 ms 8184 KB Output is correct
100 Correct 101 ms 8184 KB Output is correct
101 Correct 100 ms 8184 KB Output is correct
102 Correct 103 ms 8184 KB Output is correct
103 Correct 101 ms 8188 KB Output is correct
104 Correct 98 ms 8184 KB Output is correct
105 Correct 103 ms 8184 KB Output is correct