답안 #794220

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
794220 2023-07-26T11:01:22 Z MODDI 슈퍼트리 잇기 (IOI20_supertrees) C++14
21 / 100
204 ms 22036 KB
#include "supertrees.h"
#include <bits/stdc++.h>
//#include "grader.cpp"
using namespace std;
#define pb push_back
#define mp make_pair
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;
struct DSU{
	vi parent, size;
	vector<bool> kec, dvojka;
	void init(int n){
		kec.resize(n, false);
		dvojka.resize(n, false);
		for(int i = 0; i < n; i++){
			parent.pb(i);
			size.pb(1);
		}
	}
	bool ok(int v){
		if(dvojka[v] && kec[v])	return false;
		return true;
	}
	bool is_dva(int v){
		return dvojka[v];
	}
	int get_size(int v){
		return size[v];
	}
	int find_parent(int v){
		if(parent[v] == v)	return v;
		return parent[v] = find_parent(parent[v]);
	}
	void merge(int a, int b, int tip){
		a = find_parent(a);
		b = find_parent(b);
		bool done = false;
		if(a != b){
			if(size[b] > size[a])
				swap(a, b);
			
			done = true;
			if(tip == 1)	kec[a] = true;
			if(tip == 2)	dvojka[a] = true;	
			parent[b] = a;
			size[a] += size[b];
		}
		if(!done){
			if(tip == 1)	kec[a] = true;
			if(tip == 2) 	dvojka[a] = true;
		}
	}
};
int construct(vector<vi> p) {
	int n = p.size();
	vector<vi> answer;
	bool possible = true;
	for(int i = 0; i < n; i++){
		for(auto t : p[i]){
			if(t == 3)	possible = false;
		}
	}
	for(int i = 0; i < n; i++){
		vi pom(n,0);
		answer.pb(pom);
	}
	DSU dsu;
	dsu.init(n);
	for(int i = 0; i < n; i++){
		for(int j = i+1; j < n; j++){
			if(p[i][j]>=1 && p[i][j]<=2){
				dsu.merge(i, j, p[i][j]);
				dsu.merge(j, i, p[i][j]);
			}
			else
				continue;
		}
	}
	for(int i = 0; i < n; i++){
		for(int j = i + 1; j < n; j++){
			if(p[i][j] == 0 && dsu.find_parent(i) == dsu.find_parent(j)){
				possible = false;
			}
		}
	}
	for(int i = 0; i < n; i++){
		int a = dsu.find_parent(i);
		if(!dsu.ok(a))
			possible = false;
	}
	int last[n], first[n];
	memset(first, -1, sizeof first);
	memset(last, -1, sizeof last);
	for(int i = 0; i < n; i++){
		int a = dsu.find_parent(i);
		if(last[a] == -1){	
			last[a] = i;
			first[a] = i;
		}
		else{
			answer[i][last[a]] = 1;
			answer[last[a]][i] = 1;
			last[a] = i;
		}
	}
	for(int i = 0; i < n; i++){
		int a = dsu.find_parent(i);
		if(dsu.is_dva(a) && first[a] != last[a]){
			answer[first[a]][last[a]] = 1;
			answer[last[a]][first[a]] = 1;
 		}
 		else if(dsu.is_dva(a) && dsu.get_size(a) <=2)possible=false;
	}
	if(!possible)	return 0;
	build(answer);
	return 1;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 7 ms 1108 KB Output is correct
7 Correct 165 ms 22016 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 7 ms 1108 KB Output is correct
7 Correct 165 ms 22016 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 7 ms 1108 KB Output is correct
13 Correct 157 ms 22036 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 4 ms 724 KB Output is correct
17 Correct 82 ms 12044 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
19 Correct 0 ms 212 KB Output is correct
20 Correct 42 ms 5708 KB Output is correct
21 Correct 160 ms 21964 KB Output is correct
22 Correct 155 ms 22016 KB Output is correct
23 Correct 204 ms 21964 KB Output is correct
24 Correct 188 ms 22036 KB Output is correct
25 Correct 70 ms 12048 KB Output is correct
26 Correct 68 ms 12052 KB Output is correct
27 Correct 164 ms 21984 KB Output is correct
28 Correct 156 ms 22020 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Incorrect 0 ms 212 KB Answer gives possible 1 while actual possible 0
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 40 ms 5724 KB Output is correct
5 Correct 157 ms 22020 KB Output is correct
6 Correct 155 ms 22036 KB Output is correct
7 Correct 165 ms 22012 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 41 ms 5684 KB Output is correct
10 Correct 165 ms 22024 KB Output is correct
11 Correct 159 ms 22020 KB Output is correct
12 Correct 168 ms 22036 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Incorrect 0 ms 212 KB Answer gives possible 0 while actual possible 1
16 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 7 ms 1108 KB Output is correct
7 Correct 165 ms 22016 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 7 ms 1108 KB Output is correct
13 Correct 157 ms 22036 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 4 ms 724 KB Output is correct
17 Correct 82 ms 12044 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
19 Correct 0 ms 212 KB Output is correct
20 Correct 42 ms 5708 KB Output is correct
21 Correct 160 ms 21964 KB Output is correct
22 Correct 155 ms 22016 KB Output is correct
23 Correct 204 ms 21964 KB Output is correct
24 Correct 188 ms 22036 KB Output is correct
25 Correct 70 ms 12048 KB Output is correct
26 Correct 68 ms 12052 KB Output is correct
27 Correct 164 ms 21984 KB Output is correct
28 Correct 156 ms 22020 KB Output is correct
29 Correct 0 ms 212 KB Output is correct
30 Correct 0 ms 212 KB Output is correct
31 Correct 0 ms 212 KB Output is correct
32 Incorrect 0 ms 212 KB Answer gives possible 1 while actual possible 0
33 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 7 ms 1108 KB Output is correct
7 Correct 165 ms 22016 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 7 ms 1108 KB Output is correct
13 Correct 157 ms 22036 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 4 ms 724 KB Output is correct
17 Correct 82 ms 12044 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
19 Correct 0 ms 212 KB Output is correct
20 Correct 42 ms 5708 KB Output is correct
21 Correct 160 ms 21964 KB Output is correct
22 Correct 155 ms 22016 KB Output is correct
23 Correct 204 ms 21964 KB Output is correct
24 Correct 188 ms 22036 KB Output is correct
25 Correct 70 ms 12048 KB Output is correct
26 Correct 68 ms 12052 KB Output is correct
27 Correct 164 ms 21984 KB Output is correct
28 Correct 156 ms 22020 KB Output is correct
29 Correct 0 ms 212 KB Output is correct
30 Correct 0 ms 212 KB Output is correct
31 Correct 0 ms 212 KB Output is correct
32 Incorrect 0 ms 212 KB Answer gives possible 1 while actual possible 0
33 Halted 0 ms 0 KB -