답안 #1024158

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1024158 2024-07-15T14:17:05 Z XJP12 슈퍼트리 잇기 (IOI20_supertrees) C++14
21 / 100
133 ms 24232 KB
#include <bits/stdc++.h>
#include "supertrees.h"
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
int m;
struct UF{
	vi e;
	vi con;
	UF(int n){ e.assign(n,-1); con.assign(n,0);}
 
	int find(int x){ return (e[x] < 0 ? x : find(e[x])); }
 
	void _union(int a, int b){
		int x = find(a);
		int y = find(b);
		if(x == y) return;
		if(e[x] > e[y]) swap(x,y);
		e[x] += e[y];
		e[y] = x;
	}
};
int construct(vvi p){
	m = (int)p.size();
	int ban=0;
	UF fu(m);
	vvi ans(m, vi(m,0));
	vector<set<int>> coneect(m, set<int>());
	vvi conect(m, vi());
	for(int i=0; i<m; i++){
		for(int j=i; j<m; j++){
			if(i==j)  continue;
			if(p[i][j]==1 && ban==0){
				ban=1;
			}
			if(p[i][j]==2 && ban==0){
				ban=2;
			}
			if(p[i][j]!=0){
				fu._union(i, j);
			}
		}
	}
	for(int i=0; i<m; i++){
		for(int j=i; j<m; j++){
			if(p[i][j]==0){
				if(fu.find(i)==fu.find(j)){
					return 0;
				}
			}else{
				int t = fu.find(i);
				int size=(int)coneect[t].size();
				coneect[t].insert(i);
				if((int)coneect[t].size() > size) {conect[t].push_back(i); size++;}
				coneect[t].insert(j);
				if((int)coneect[t].size() > size) {conect[t].push_back(j); size++;}
			}
		}
	}
	for(int i=0; i<m; i++){
		if(ban==2 && (int)conect[i].size()==2){
			return 0;
		}
		for(int j=0; j<(int)conect[i].size()-1; j++){
			ans[conect[i][j+1]][conect[i][j]]=1;
			ans[conect[i][j]][conect[i][j+1]]=1;
		}
	/*	if(ban==2){
			ans[conect[i][(int)conect.size()-1]][conect[i][0]]=1;
			ans[conect[i][0]][conect[i][(int)conect.size()-1]]=1;
		}*/
	}
	for(int i=0; i<m; i++){
		ans[i][i]=0;
	}
	build(ans);
	return 1;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 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 1 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 6 ms 1188 KB Output is correct
7 Correct 133 ms 24196 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 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 1 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 6 ms 1188 KB Output is correct
7 Correct 133 ms 24196 KB Output is correct
8 Correct 0 ms 344 KB Output is correct
9 Correct 1 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 1364 KB Output is correct
13 Correct 113 ms 24072 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 0 ms 436 KB Output is correct
16 Correct 3 ms 932 KB Output is correct
17 Correct 58 ms 14068 KB Output is correct
18 Correct 1 ms 344 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 32 ms 6236 KB Output is correct
21 Correct 121 ms 24196 KB Output is correct
22 Correct 115 ms 24148 KB Output is correct
23 Correct 131 ms 24148 KB Output is correct
24 Correct 111 ms 24232 KB Output is correct
25 Correct 49 ms 14220 KB Output is correct
26 Correct 53 ms 14160 KB Output is correct
27 Correct 128 ms 24144 KB Output is correct
28 Correct 116 ms 24124 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 Correct 0 ms 348 KB Output is correct
5 Incorrect 0 ms 348 KB Too few ways to get from 0 to 1, should be 2 found 1
6 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 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 -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 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 1 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 6 ms 1188 KB Output is correct
7 Correct 133 ms 24196 KB Output is correct
8 Correct 0 ms 344 KB Output is correct
9 Correct 1 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 1364 KB Output is correct
13 Correct 113 ms 24072 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 0 ms 436 KB Output is correct
16 Correct 3 ms 932 KB Output is correct
17 Correct 58 ms 14068 KB Output is correct
18 Correct 1 ms 344 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 32 ms 6236 KB Output is correct
21 Correct 121 ms 24196 KB Output is correct
22 Correct 115 ms 24148 KB Output is correct
23 Correct 131 ms 24148 KB Output is correct
24 Correct 111 ms 24232 KB Output is correct
25 Correct 49 ms 14220 KB Output is correct
26 Correct 53 ms 14160 KB Output is correct
27 Correct 128 ms 24144 KB Output is correct
28 Correct 116 ms 24124 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 Correct 0 ms 348 KB Output is correct
33 Incorrect 0 ms 348 KB Too few ways to get from 0 to 1, should be 2 found 1
34 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 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 1 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 6 ms 1188 KB Output is correct
7 Correct 133 ms 24196 KB Output is correct
8 Correct 0 ms 344 KB Output is correct
9 Correct 1 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 1364 KB Output is correct
13 Correct 113 ms 24072 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 0 ms 436 KB Output is correct
16 Correct 3 ms 932 KB Output is correct
17 Correct 58 ms 14068 KB Output is correct
18 Correct 1 ms 344 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 32 ms 6236 KB Output is correct
21 Correct 121 ms 24196 KB Output is correct
22 Correct 115 ms 24148 KB Output is correct
23 Correct 131 ms 24148 KB Output is correct
24 Correct 111 ms 24232 KB Output is correct
25 Correct 49 ms 14220 KB Output is correct
26 Correct 53 ms 14160 KB Output is correct
27 Correct 128 ms 24144 KB Output is correct
28 Correct 116 ms 24124 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 Correct 0 ms 348 KB Output is correct
33 Incorrect 0 ms 348 KB Too few ways to get from 0 to 1, should be 2 found 1
34 Halted 0 ms 0 KB -