답안 #998116

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
998116 2024-06-13T10:02:56 Z Arapak 슈퍼트리 잇기 (IOI20_supertrees) C++17
21 / 100
164 ms 22124 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_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;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 5 ms 1276 KB Output is correct
7 Correct 127 ms 22024 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 5 ms 1276 KB Output is correct
7 Correct 127 ms 22024 KB Output is correct
8 Correct 0 ms 344 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 1116 KB Output is correct
13 Correct 125 ms 21996 KB Output is correct
14 Correct 0 ms 344 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 3 ms 852 KB Output is correct
17 Correct 62 ms 12040 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 42 ms 5712 KB Output is correct
21 Correct 142 ms 22040 KB Output is correct
22 Correct 121 ms 22124 KB Output is correct
23 Correct 164 ms 22096 KB Output is correct
24 Correct 122 ms 22096 KB Output is correct
25 Correct 62 ms 12036 KB Output is correct
26 Correct 75 ms 12040 KB Output is correct
27 Correct 126 ms 22040 KB Output is correct
28 Correct 120 ms 22100 KB Output is correct
# 결과 실행 시간 메모리 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 Incorrect 0 ms 348 KB Answer gives possible 1 while actual possible 0
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 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 -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 5 ms 1276 KB Output is correct
7 Correct 127 ms 22024 KB Output is correct
8 Correct 0 ms 344 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 1116 KB Output is correct
13 Correct 125 ms 21996 KB Output is correct
14 Correct 0 ms 344 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 3 ms 852 KB Output is correct
17 Correct 62 ms 12040 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 42 ms 5712 KB Output is correct
21 Correct 142 ms 22040 KB Output is correct
22 Correct 121 ms 22124 KB Output is correct
23 Correct 164 ms 22096 KB Output is correct
24 Correct 122 ms 22096 KB Output is correct
25 Correct 62 ms 12036 KB Output is correct
26 Correct 75 ms 12040 KB Output is correct
27 Correct 126 ms 22040 KB Output is correct
28 Correct 120 ms 22100 KB Output is correct
29 Correct 0 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 -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 5 ms 1276 KB Output is correct
7 Correct 127 ms 22024 KB Output is correct
8 Correct 0 ms 344 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 1116 KB Output is correct
13 Correct 125 ms 21996 KB Output is correct
14 Correct 0 ms 344 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 3 ms 852 KB Output is correct
17 Correct 62 ms 12040 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 42 ms 5712 KB Output is correct
21 Correct 142 ms 22040 KB Output is correct
22 Correct 121 ms 22124 KB Output is correct
23 Correct 164 ms 22096 KB Output is correct
24 Correct 122 ms 22096 KB Output is correct
25 Correct 62 ms 12036 KB Output is correct
26 Correct 75 ms 12040 KB Output is correct
27 Correct 126 ms 22040 KB Output is correct
28 Correct 120 ms 22100 KB Output is correct
29 Correct 0 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 -