답안 #998120

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
998120 2024-06-13T10:10:00 Z Arapak 슈퍼트리 잇기 (IOI20_supertrees) C++17
56 / 100
169 ms 24152 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;
		}
		if(sz(cycles[i]) >= 3) {
			answer[cycles[i].back()][cycles[i][0]] = true;
			answer[cycles[i][0]][cycles[i].back()] = true;
		}
	}

	build(answer);
	return 1;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 7 ms 1116 KB Output is correct
7 Correct 120 ms 22032 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 7 ms 1116 KB Output is correct
7 Correct 120 ms 22032 KB Output is correct
8 Correct 1 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 1112 KB Output is correct
13 Correct 121 ms 22068 KB Output is correct
14 Correct 0 ms 344 KB Output is correct
15 Correct 1 ms 348 KB Output is correct
16 Correct 3 ms 860 KB Output is correct
17 Correct 60 ms 12116 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 5728 KB Output is correct
21 Correct 125 ms 22096 KB Output is correct
22 Correct 118 ms 21992 KB Output is correct
23 Correct 129 ms 22036 KB Output is correct
24 Correct 129 ms 22096 KB Output is correct
25 Correct 107 ms 12116 KB Output is correct
26 Correct 50 ms 12112 KB Output is correct
27 Correct 129 ms 22100 KB Output is correct
28 Correct 119 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 1 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 Correct 0 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 47 ms 6248 KB Output is correct
5 Correct 130 ms 24152 KB Output is correct
6 Correct 131 ms 24148 KB Output is correct
7 Correct 169 ms 23932 KB Output is correct
8 Correct 1 ms 344 KB Output is correct
9 Correct 31 ms 6300 KB Output is correct
10 Correct 125 ms 24068 KB Output is correct
11 Correct 160 ms 23980 KB Output is correct
12 Correct 131 ms 24148 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 1 ms 344 KB Output is correct
15 Correct 1 ms 348 KB Output is correct
16 Correct 45 ms 6276 KB Output is correct
17 Correct 121 ms 24144 KB Output is correct
18 Correct 126 ms 24144 KB Output is correct
19 Correct 135 ms 23928 KB Output is correct
20 Correct 138 ms 24148 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 7 ms 1116 KB Output is correct
7 Correct 120 ms 22032 KB Output is correct
8 Correct 1 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 1112 KB Output is correct
13 Correct 121 ms 22068 KB Output is correct
14 Correct 0 ms 344 KB Output is correct
15 Correct 1 ms 348 KB Output is correct
16 Correct 3 ms 860 KB Output is correct
17 Correct 60 ms 12116 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 5728 KB Output is correct
21 Correct 125 ms 22096 KB Output is correct
22 Correct 118 ms 21992 KB Output is correct
23 Correct 129 ms 22036 KB Output is correct
24 Correct 129 ms 22096 KB Output is correct
25 Correct 107 ms 12116 KB Output is correct
26 Correct 50 ms 12112 KB Output is correct
27 Correct 129 ms 22100 KB Output is correct
28 Correct 119 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 1 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 344 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 7 ms 1116 KB Output is correct
7 Correct 120 ms 22032 KB Output is correct
8 Correct 1 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 1112 KB Output is correct
13 Correct 121 ms 22068 KB Output is correct
14 Correct 0 ms 344 KB Output is correct
15 Correct 1 ms 348 KB Output is correct
16 Correct 3 ms 860 KB Output is correct
17 Correct 60 ms 12116 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 5728 KB Output is correct
21 Correct 125 ms 22096 KB Output is correct
22 Correct 118 ms 21992 KB Output is correct
23 Correct 129 ms 22036 KB Output is correct
24 Correct 129 ms 22096 KB Output is correct
25 Correct 107 ms 12116 KB Output is correct
26 Correct 50 ms 12112 KB Output is correct
27 Correct 129 ms 22100 KB Output is correct
28 Correct 119 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 1 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 -