Submission #301608

# Submission time Handle Problem Language Result Execution time Memory
301608 2020-09-18T05:18:00 Z Namnamseo Connecting Supertrees (IOI20_supertrees) C++17
56 / 100
302 ms 22264 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) 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) {
      |                  ^~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
3 Correct 0 ms 384 KB Output is correct
4 Correct 1 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 275 ms 22160 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
3 Correct 0 ms 384 KB Output is correct
4 Correct 1 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 275 ms 22160 KB Output is correct
8 Correct 1 ms 384 KB Output is correct
9 Correct 1 ms 512 KB Output is correct
10 Correct 1 ms 384 KB Output is correct
11 Correct 1 ms 384 KB Output is correct
12 Correct 11 ms 1152 KB Output is correct
13 Correct 257 ms 18296 KB Output is correct
14 Correct 0 ms 384 KB Output is correct
15 Correct 1 ms 384 KB Output is correct
16 Correct 6 ms 640 KB Output is correct
17 Correct 128 ms 8184 KB Output is correct
18 Correct 0 ms 384 KB Output is correct
19 Correct 1 ms 384 KB Output is correct
20 Correct 67 ms 6864 KB Output is correct
21 Correct 269 ms 22136 KB Output is correct
22 Correct 279 ms 21752 KB Output is correct
23 Correct 284 ms 22140 KB Output is correct
24 Correct 252 ms 18604 KB Output is correct
25 Correct 119 ms 8312 KB Output is correct
26 Correct 115 ms 8184 KB Output is correct
27 Correct 286 ms 22264 KB Output is correct
28 Correct 257 ms 18552 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Incorrect 1 ms 384 KB Answer gives possible 1 while actual possible 0
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 67 ms 6648 KB Output is correct
5 Correct 271 ms 22136 KB Output is correct
6 Correct 282 ms 21752 KB Output is correct
7 Correct 302 ms 22264 KB Output is correct
8 Correct 1 ms 384 KB Output is correct
9 Correct 66 ms 6648 KB Output is correct
10 Correct 270 ms 22136 KB Output is correct
11 Correct 265 ms 22140 KB Output is correct
12 Correct 278 ms 22136 KB Output is correct
13 Correct 1 ms 384 KB Output is correct
14 Correct 1 ms 384 KB Output is correct
15 Correct 1 ms 384 KB Output is correct
16 Correct 65 ms 6648 KB Output is correct
17 Correct 272 ms 22136 KB Output is correct
18 Correct 260 ms 22008 KB Output is correct
19 Correct 278 ms 22136 KB Output is correct
20 Correct 282 ms 18440 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
3 Correct 0 ms 384 KB Output is correct
4 Correct 1 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 275 ms 22160 KB Output is correct
8 Correct 1 ms 384 KB Output is correct
9 Correct 1 ms 512 KB Output is correct
10 Correct 1 ms 384 KB Output is correct
11 Correct 1 ms 384 KB Output is correct
12 Correct 11 ms 1152 KB Output is correct
13 Correct 257 ms 18296 KB Output is correct
14 Correct 0 ms 384 KB Output is correct
15 Correct 1 ms 384 KB Output is correct
16 Correct 6 ms 640 KB Output is correct
17 Correct 128 ms 8184 KB Output is correct
18 Correct 0 ms 384 KB Output is correct
19 Correct 1 ms 384 KB Output is correct
20 Correct 67 ms 6864 KB Output is correct
21 Correct 269 ms 22136 KB Output is correct
22 Correct 279 ms 21752 KB Output is correct
23 Correct 284 ms 22140 KB Output is correct
24 Correct 252 ms 18604 KB Output is correct
25 Correct 119 ms 8312 KB Output is correct
26 Correct 115 ms 8184 KB Output is correct
27 Correct 286 ms 22264 KB Output is correct
28 Correct 257 ms 18552 KB Output is correct
29 Correct 1 ms 384 KB Output is correct
30 Correct 1 ms 384 KB Output is correct
31 Correct 1 ms 384 KB Output is correct
32 Incorrect 1 ms 384 KB Answer gives possible 1 while actual possible 0
33 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
3 Correct 0 ms 384 KB Output is correct
4 Correct 1 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 275 ms 22160 KB Output is correct
8 Correct 1 ms 384 KB Output is correct
9 Correct 1 ms 512 KB Output is correct
10 Correct 1 ms 384 KB Output is correct
11 Correct 1 ms 384 KB Output is correct
12 Correct 11 ms 1152 KB Output is correct
13 Correct 257 ms 18296 KB Output is correct
14 Correct 0 ms 384 KB Output is correct
15 Correct 1 ms 384 KB Output is correct
16 Correct 6 ms 640 KB Output is correct
17 Correct 128 ms 8184 KB Output is correct
18 Correct 0 ms 384 KB Output is correct
19 Correct 1 ms 384 KB Output is correct
20 Correct 67 ms 6864 KB Output is correct
21 Correct 269 ms 22136 KB Output is correct
22 Correct 279 ms 21752 KB Output is correct
23 Correct 284 ms 22140 KB Output is correct
24 Correct 252 ms 18604 KB Output is correct
25 Correct 119 ms 8312 KB Output is correct
26 Correct 115 ms 8184 KB Output is correct
27 Correct 286 ms 22264 KB Output is correct
28 Correct 257 ms 18552 KB Output is correct
29 Correct 1 ms 384 KB Output is correct
30 Correct 1 ms 384 KB Output is correct
31 Correct 1 ms 384 KB Output is correct
32 Incorrect 1 ms 384 KB Answer gives possible 1 while actual possible 0
33 Halted 0 ms 0 KB -