답안 #1039720

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1039720 2024-07-31T08:07:36 Z amirhoseinfar1385 슈퍼트리 잇기 (IOI20_supertrees) C++17
56 / 100
179 ms 22388 KB
#include "supertrees.h"
#include<bits/stdc++.h>
using namespace std;
const int maxn=1000+10;
int n,vis[maxn];
vector<vector<int>>res;

struct dsu{
	int par[maxn];
	vector<int>adj[maxn];
	dsu(){
		for(int i=0;i<maxn;i++){
			par[i]=i;
		}
	}
	int root(int u){
		if(u==par[u]){
			return u;
		}
		return par[u]=root(par[u]);
	}
	void con(int u,int v){
		u=root(u),v=root(v);
		if(u!=v){
			par[u]=v;
			adj[v].push_back(u);
		}
	}
	vector<int>ret;
	void dfs(int u,int par=-1){
		ret.push_back(u);
		for(auto x:adj[u]){
			if(x==par){
				continue;
			}
			dfs(x,u);
		}
	}
	vector<int>allc(int u){
		ret.clear();
		u=root(u);
		dfs(u);
		return ret;
	}
}ds1,ds2;

void adde(int u,int v){
	res[u][v]=res[v][u]=1;
}

void addp(vector<int>a){
	for(int i=1;i<(int)a.size();i++){
		adde(a[i-1],a[i]);
	}
}

int construct(std::vector<std::vector<int>> p) {
	n = p.size();
	res.resize(n,vector<int>(n));
	for(int i=0;i<n;i++){
		for(int j=0;j<n;j++){
			if(p[i][j]==1){
				ds1.con(i,j);
			}
		}
	}
	for(int i=0;i<n;i++){
		if(vis[i]==0){
			vector<int>hey=ds1.allc(i);
			for(auto x:hey){
				vis[x]=1;
			}
			addp(hey);
		}
	}
	for(int i=0;i<n;i++){
		for(int j=0;j<n;j++){
			if(p[i][j]==2){
				ds2.con(ds1.root(i),ds1.root(j));
			}
		}
		vis[i]=0;
	}
	for(int i=0;i<n;i++){
		if(vis[i]==0){
			vector<int>hey=ds2.allc(i);
			for(auto x:hey){
				vis[x]=1;
			}
			addp(hey);
			if((int)hey.size()>1){
				adde(hey[0],hey.back());
			}
		}
	}
	int retrr=1;
	for(int i=0;i<n;i++){
		for(int j=0;j<n;j++){
			if(p[i][j]==1&&ds1.root(i)!=ds1.root(j)){
				retrr=-1;
			}
			if(p[i][j]==0&&(ds1.root(i)==ds1.root(j)||ds2.root(i)==ds2.root(j))){
				retrr=-1;
			}
			if(p[i][j]==2&&(ds2.root(ds1.root(i))!=ds2.root(ds1.root(j))||ds1.root(i)==ds1.root(j))){
				retrr=-1;
			}
		}
	}
	if(retrr==-1){
		return 0;
	}
	build(res);
	return retrr;
}
# 결과 실행 시간 메모리 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 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 8 ms 1372 KB Output is correct
7 Correct 118 ms 22100 KB Output is correct
# 결과 실행 시간 메모리 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 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 8 ms 1372 KB Output is correct
7 Correct 118 ms 22100 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 1 ms 348 KB Output is correct
12 Correct 5 ms 1372 KB Output is correct
13 Correct 143 ms 22088 KB Output is correct
14 Correct 1 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 71 ms 12364 KB Output is correct
18 Correct 1 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 29 ms 5968 KB Output is correct
21 Correct 171 ms 22088 KB Output is correct
22 Correct 119 ms 22088 KB Output is correct
23 Correct 128 ms 22100 KB Output is correct
24 Correct 144 ms 22100 KB Output is correct
25 Correct 62 ms 12352 KB Output is correct
26 Correct 58 ms 12116 KB Output is correct
27 Correct 134 ms 22100 KB Output is correct
28 Correct 122 ms 22100 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Incorrect 1 ms 348 KB Answer gives possible 1 while actual possible 0
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 31 ms 5808 KB Output is correct
5 Correct 126 ms 22096 KB Output is correct
6 Correct 132 ms 22084 KB Output is correct
7 Correct 161 ms 22288 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 39 ms 5936 KB Output is correct
10 Correct 130 ms 22100 KB Output is correct
11 Correct 119 ms 22092 KB Output is correct
12 Correct 133 ms 22100 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 56 ms 5836 KB Output is correct
17 Correct 124 ms 22092 KB Output is correct
18 Correct 179 ms 22080 KB Output is correct
19 Correct 125 ms 22096 KB Output is correct
20 Correct 125 ms 22388 KB Output is correct
# 결과 실행 시간 메모리 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 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 8 ms 1372 KB Output is correct
7 Correct 118 ms 22100 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 1 ms 348 KB Output is correct
12 Correct 5 ms 1372 KB Output is correct
13 Correct 143 ms 22088 KB Output is correct
14 Correct 1 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 71 ms 12364 KB Output is correct
18 Correct 1 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 29 ms 5968 KB Output is correct
21 Correct 171 ms 22088 KB Output is correct
22 Correct 119 ms 22088 KB Output is correct
23 Correct 128 ms 22100 KB Output is correct
24 Correct 144 ms 22100 KB Output is correct
25 Correct 62 ms 12352 KB Output is correct
26 Correct 58 ms 12116 KB Output is correct
27 Correct 134 ms 22100 KB Output is correct
28 Correct 122 ms 22100 KB Output is correct
29 Correct 1 ms 348 KB Output is correct
30 Correct 1 ms 348 KB Output is correct
31 Correct 0 ms 348 KB Output is correct
32 Incorrect 1 ms 348 KB Answer gives possible 1 while actual possible 0
33 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 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 8 ms 1372 KB Output is correct
7 Correct 118 ms 22100 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 1 ms 348 KB Output is correct
12 Correct 5 ms 1372 KB Output is correct
13 Correct 143 ms 22088 KB Output is correct
14 Correct 1 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 71 ms 12364 KB Output is correct
18 Correct 1 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 29 ms 5968 KB Output is correct
21 Correct 171 ms 22088 KB Output is correct
22 Correct 119 ms 22088 KB Output is correct
23 Correct 128 ms 22100 KB Output is correct
24 Correct 144 ms 22100 KB Output is correct
25 Correct 62 ms 12352 KB Output is correct
26 Correct 58 ms 12116 KB Output is correct
27 Correct 134 ms 22100 KB Output is correct
28 Correct 122 ms 22100 KB Output is correct
29 Correct 1 ms 348 KB Output is correct
30 Correct 1 ms 348 KB Output is correct
31 Correct 0 ms 348 KB Output is correct
32 Incorrect 1 ms 348 KB Answer gives possible 1 while actual possible 0
33 Halted 0 ms 0 KB -