Submission #998118

# Submission time Handle Problem Language Result Execution time Memory
998118 2024-06-13T10:04:06 Z Arapak Connecting Supertrees (IOI20_supertrees) C++17
21 / 100
130 ms 22148 KB
// Author: Kajetan Ramsza
#include "bits/stdc++.h"
#include "supertrees.h"
using namespace std;

#define rep(i, a, b) for(int i = (a); i < (b); ++i)
#define all(x) begin(x), end(x)
#define sz(x) (int)(x).size()
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;

template<typename F, typename S> ostream& operator<<(ostream& os, const pair<F, S> &p) { return os<<"("<<p.first<<", "<<p.second<<")"; }
template<typename T> ostream &operator<<(ostream & os, const vector<T> &v) { os << "{"; typename vector< T > :: const_iterator it;
    for( it = v.begin(); it != v.end(); it++ ) { if( it != v.begin() ) os << ", "; os << *it; } return os << "}"; }

void dbg_out() { cerr<<'\n'; }
template<typename Head, typename... Tail> void dbg_out(Head H, Tail... T) { cerr<<' '<<H; dbg_out(T...); }

#ifdef DEBUG
#define dbg(...) cerr<<"(" << #__VA_ARGS__ <<"):", dbg_out(__VA_ARGS__)
#else
#define dbg(...) 
#endif

struct DSU {
	vi dsu, siz;

	DSU(int n) : dsu(n), siz(n, 1) {
		iota(all(dsu), 0);
	}

	int find(int x) {
		if(dsu[x] == x) return x;
		return dsu[x] = find(dsu[x]);
	}

	void merge(int a, int b) {
		a = find(a); b = find(b);
		if(a == b) return;
		if(siz[a] < siz[b]) swap(a, b);
		else if(siz[a] == siz[b]) siz[a]++;
		dsu[b] = a;
	}

	bool same(int a, int b) {
		return find(a) == find(b);
	}
};

int n;
vector<vi> answer;

pair<bool, vi> find_connected(vector<vi> &p) {
	DSU dsu(n);
	rep(i,0,n) rep(j,0,n) 
		if(p[i][j] > 0) dsu.merge(i, j);

	rep(i,0,n) rep(j,0,n)
		if(p[i][j] == 0 && dsu.same(i, j))
			return {false, {}};
	return {true, dsu.dsu}; 
}

pair<bool, vi> find_one_connected(vector<vi> &p) {
	DSU dsu(n);
	rep(i,0,n) rep(j,0,n) 
		if(p[i][j] == 1) dsu.merge(i, j);

	rep(i,0,n) rep(j,0,n)
		if(p[i][j] != 1 && dsu.same(i, j))
			return {false, {}};
	return {true, dsu.dsu}; 
}

int construct(vector<vi> p) {
	n = p.size();
	answer.assign(n, vi(n, 0));
	auto [correct, conn] = find_connected(p);
	if(!correct) return 0;

	auto [one_correct, one_conn] = find_one_connected(p);
	if(!one_correct) return 0;

	rep(i,0,n) {
		if(one_conn[i] == i) continue;
		answer[i][one_conn[i]] = 1;
		answer[one_conn[i]][i] = 1;
	}

	vector<vi> cycles(n);
	rep(i,0,n) if(one_conn[i] == i) 
		cycles[conn[i]].push_back(i);

	rep(i,0,n)
		rep(j,1,sz(cycles[i])) {
			answer[cycles[i][j]][cycles[i][j-1]] = true;
			answer[cycles[i][j-1]][cycles[i][j]] = true;
		}

	build(answer);
	return 1;
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 344 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 5 ms 1184 KB Output is correct
7 Correct 123 ms 22100 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 344 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 5 ms 1184 KB Output is correct
7 Correct 123 ms 22100 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 5 ms 1304 KB Output is correct
13 Correct 122 ms 22148 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 3 ms 860 KB Output is correct
17 Correct 65 ms 12036 KB Output is correct
18 Correct 0 ms 344 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 33 ms 5712 KB Output is correct
21 Correct 122 ms 22100 KB Output is correct
22 Correct 123 ms 22096 KB Output is correct
23 Correct 130 ms 22096 KB Output is correct
24 Correct 119 ms 22096 KB Output is correct
25 Correct 58 ms 12116 KB Output is correct
26 Correct 52 ms 12052 KB Output is correct
27 Correct 128 ms 22096 KB Output is correct
28 Correct 121 ms 22032 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Incorrect 0 ms 348 KB Answer gives possible 1 while actual possible 0
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Incorrect 0 ms 348 KB Too few ways to get from 0 to 1, should be 2 found 1
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 344 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 5 ms 1184 KB Output is correct
7 Correct 123 ms 22100 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 5 ms 1304 KB Output is correct
13 Correct 122 ms 22148 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 3 ms 860 KB Output is correct
17 Correct 65 ms 12036 KB Output is correct
18 Correct 0 ms 344 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 33 ms 5712 KB Output is correct
21 Correct 122 ms 22100 KB Output is correct
22 Correct 123 ms 22096 KB Output is correct
23 Correct 130 ms 22096 KB Output is correct
24 Correct 119 ms 22096 KB Output is correct
25 Correct 58 ms 12116 KB Output is correct
26 Correct 52 ms 12052 KB Output is correct
27 Correct 128 ms 22096 KB Output is correct
28 Correct 121 ms 22032 KB Output is correct
29 Correct 1 ms 344 KB Output is correct
30 Correct 0 ms 348 KB Output is correct
31 Correct 0 ms 348 KB Output is correct
32 Incorrect 0 ms 348 KB Answer gives possible 1 while actual possible 0
33 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 344 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 5 ms 1184 KB Output is correct
7 Correct 123 ms 22100 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 5 ms 1304 KB Output is correct
13 Correct 122 ms 22148 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 3 ms 860 KB Output is correct
17 Correct 65 ms 12036 KB Output is correct
18 Correct 0 ms 344 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 33 ms 5712 KB Output is correct
21 Correct 122 ms 22100 KB Output is correct
22 Correct 123 ms 22096 KB Output is correct
23 Correct 130 ms 22096 KB Output is correct
24 Correct 119 ms 22096 KB Output is correct
25 Correct 58 ms 12116 KB Output is correct
26 Correct 52 ms 12052 KB Output is correct
27 Correct 128 ms 22096 KB Output is correct
28 Correct 121 ms 22032 KB Output is correct
29 Correct 1 ms 344 KB Output is correct
30 Correct 0 ms 348 KB Output is correct
31 Correct 0 ms 348 KB Output is correct
32 Incorrect 0 ms 348 KB Answer gives possible 1 while actual possible 0
33 Halted 0 ms 0 KB -