답안 #1052776

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1052776 2024-08-10T21:16:21 Z amirhoseinfar1385 슈퍼트리 잇기 (IOI20_supertrees) C++17
100 / 100
135 ms 24248 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]==3){
           return 0;
         }	
          if(i==j){
				continue;
			}
			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;
	}
	int retrr=1;
	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()>2){
				adde(hey[0],hey.back());
			}
			if((int)hey.size()==2){
				retrr=-1;
			}
		}
	}
	for(int i=0;i<n;i++){
		for(int j=0;j<n;j++){
			if(i==j){
				continue;
			}
			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(ds1.root(i))==ds2.root(ds1.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 0 ms 348 KB Output is correct
4 Correct 1 ms 344 KB Output is correct
5 Correct 1 ms 344 KB Output is correct
6 Correct 4 ms 1372 KB Output is correct
7 Correct 101 ms 24144 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 0 ms 348 KB Output is correct
4 Correct 1 ms 344 KB Output is correct
5 Correct 1 ms 344 KB Output is correct
6 Correct 4 ms 1372 KB Output is correct
7 Correct 101 ms 24144 KB Output is correct
8 Correct 0 ms 344 KB Output is correct
9 Correct 1 ms 344 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 1428 KB Output is correct
13 Correct 101 ms 24160 KB Output is correct
14 Correct 1 ms 344 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 3 ms 992 KB Output is correct
17 Correct 59 ms 14276 KB Output is correct
18 Correct 0 ms 344 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 26 ms 6324 KB Output is correct
21 Correct 112 ms 24144 KB Output is correct
22 Correct 117 ms 24144 KB Output is correct
23 Correct 113 ms 24244 KB Output is correct
24 Correct 111 ms 23988 KB Output is correct
25 Correct 48 ms 14208 KB Output is correct
26 Correct 46 ms 14268 KB Output is correct
27 Correct 124 ms 24128 KB Output is correct
28 Correct 101 ms 24132 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 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 Correct 0 ms 496 KB Output is correct
6 Correct 0 ms 492 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 4 ms 1248 KB Output is correct
9 Correct 99 ms 23860 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 0 ms 344 KB Output is correct
12 Correct 5 ms 1372 KB Output is correct
13 Correct 120 ms 24052 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 344 KB Output is correct
16 Correct 3 ms 856 KB Output is correct
17 Correct 68 ms 14264 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 26 ms 6300 KB Output is correct
22 Correct 102 ms 24148 KB Output is correct
23 Correct 101 ms 23992 KB Output is correct
24 Correct 123 ms 24248 KB Output is correct
25 Correct 45 ms 14164 KB Output is correct
26 Correct 51 ms 14148 KB Output is correct
27 Correct 99 ms 24168 KB Output is correct
28 Correct 121 ms 24120 KB Output is correct
29 Correct 45 ms 14164 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 27 ms 6236 KB Output is correct
5 Correct 110 ms 24144 KB Output is correct
6 Correct 107 ms 24128 KB Output is correct
7 Correct 110 ms 24064 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 32 ms 6448 KB Output is correct
10 Correct 112 ms 24148 KB Output is correct
11 Correct 100 ms 23888 KB Output is correct
12 Correct 113 ms 24040 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 28 ms 6328 KB Output is correct
17 Correct 135 ms 24132 KB Output is correct
18 Correct 105 ms 24144 KB Output is correct
19 Correct 111 ms 24040 KB Output is correct
20 Correct 105 ms 24148 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 0 ms 348 KB Output is correct
4 Correct 1 ms 344 KB Output is correct
5 Correct 1 ms 344 KB Output is correct
6 Correct 4 ms 1372 KB Output is correct
7 Correct 101 ms 24144 KB Output is correct
8 Correct 0 ms 344 KB Output is correct
9 Correct 1 ms 344 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 1428 KB Output is correct
13 Correct 101 ms 24160 KB Output is correct
14 Correct 1 ms 344 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 3 ms 992 KB Output is correct
17 Correct 59 ms 14276 KB Output is correct
18 Correct 0 ms 344 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 26 ms 6324 KB Output is correct
21 Correct 112 ms 24144 KB Output is correct
22 Correct 117 ms 24144 KB Output is correct
23 Correct 113 ms 24244 KB Output is correct
24 Correct 111 ms 23988 KB Output is correct
25 Correct 48 ms 14208 KB Output is correct
26 Correct 46 ms 14268 KB Output is correct
27 Correct 124 ms 24128 KB Output is correct
28 Correct 101 ms 24132 KB Output is correct
29 Correct 1 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 Correct 0 ms 496 KB Output is correct
34 Correct 0 ms 492 KB Output is correct
35 Correct 0 ms 348 KB Output is correct
36 Correct 4 ms 1248 KB Output is correct
37 Correct 99 ms 23860 KB Output is correct
38 Correct 1 ms 348 KB Output is correct
39 Correct 0 ms 344 KB Output is correct
40 Correct 5 ms 1372 KB Output is correct
41 Correct 120 ms 24052 KB Output is correct
42 Correct 0 ms 348 KB Output is correct
43 Correct 0 ms 344 KB Output is correct
44 Correct 3 ms 856 KB Output is correct
45 Correct 68 ms 14264 KB Output is correct
46 Correct 0 ms 348 KB Output is correct
47 Correct 0 ms 348 KB Output is correct
48 Correct 0 ms 348 KB Output is correct
49 Correct 26 ms 6300 KB Output is correct
50 Correct 102 ms 24148 KB Output is correct
51 Correct 101 ms 23992 KB Output is correct
52 Correct 123 ms 24248 KB Output is correct
53 Correct 45 ms 14164 KB Output is correct
54 Correct 51 ms 14148 KB Output is correct
55 Correct 99 ms 24168 KB Output is correct
56 Correct 121 ms 24120 KB Output is correct
57 Correct 45 ms 14164 KB Output is correct
58 Correct 0 ms 348 KB Output is correct
59 Correct 0 ms 348 KB Output is correct
60 Correct 3 ms 860 KB Output is correct
61 Correct 68 ms 14356 KB Output is correct
62 Correct 0 ms 348 KB Output is correct
63 Correct 1 ms 348 KB Output is correct
64 Correct 0 ms 348 KB Output is correct
65 Correct 31 ms 6324 KB Output is correct
66 Correct 49 ms 14316 KB Output is correct
67 Correct 52 ms 14164 KB Output is correct
68 Correct 52 ms 14164 KB Output is correct
69 Correct 47 ms 14164 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 0 ms 348 KB Output is correct
4 Correct 1 ms 344 KB Output is correct
5 Correct 1 ms 344 KB Output is correct
6 Correct 4 ms 1372 KB Output is correct
7 Correct 101 ms 24144 KB Output is correct
8 Correct 0 ms 344 KB Output is correct
9 Correct 1 ms 344 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 1428 KB Output is correct
13 Correct 101 ms 24160 KB Output is correct
14 Correct 1 ms 344 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 3 ms 992 KB Output is correct
17 Correct 59 ms 14276 KB Output is correct
18 Correct 0 ms 344 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 26 ms 6324 KB Output is correct
21 Correct 112 ms 24144 KB Output is correct
22 Correct 117 ms 24144 KB Output is correct
23 Correct 113 ms 24244 KB Output is correct
24 Correct 111 ms 23988 KB Output is correct
25 Correct 48 ms 14208 KB Output is correct
26 Correct 46 ms 14268 KB Output is correct
27 Correct 124 ms 24128 KB Output is correct
28 Correct 101 ms 24132 KB Output is correct
29 Correct 1 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 Correct 0 ms 496 KB Output is correct
34 Correct 0 ms 492 KB Output is correct
35 Correct 0 ms 348 KB Output is correct
36 Correct 4 ms 1248 KB Output is correct
37 Correct 99 ms 23860 KB Output is correct
38 Correct 1 ms 348 KB Output is correct
39 Correct 0 ms 344 KB Output is correct
40 Correct 5 ms 1372 KB Output is correct
41 Correct 120 ms 24052 KB Output is correct
42 Correct 0 ms 348 KB Output is correct
43 Correct 0 ms 344 KB Output is correct
44 Correct 3 ms 856 KB Output is correct
45 Correct 68 ms 14264 KB Output is correct
46 Correct 0 ms 348 KB Output is correct
47 Correct 0 ms 348 KB Output is correct
48 Correct 0 ms 348 KB Output is correct
49 Correct 26 ms 6300 KB Output is correct
50 Correct 102 ms 24148 KB Output is correct
51 Correct 101 ms 23992 KB Output is correct
52 Correct 123 ms 24248 KB Output is correct
53 Correct 45 ms 14164 KB Output is correct
54 Correct 51 ms 14148 KB Output is correct
55 Correct 99 ms 24168 KB Output is correct
56 Correct 121 ms 24120 KB Output is correct
57 Correct 45 ms 14164 KB Output is correct
58 Correct 1 ms 348 KB Output is correct
59 Correct 0 ms 348 KB Output is correct
60 Correct 0 ms 348 KB Output is correct
61 Correct 27 ms 6236 KB Output is correct
62 Correct 110 ms 24144 KB Output is correct
63 Correct 107 ms 24128 KB Output is correct
64 Correct 110 ms 24064 KB Output is correct
65 Correct 0 ms 348 KB Output is correct
66 Correct 32 ms 6448 KB Output is correct
67 Correct 112 ms 24148 KB Output is correct
68 Correct 100 ms 23888 KB Output is correct
69 Correct 113 ms 24040 KB Output is correct
70 Correct 0 ms 348 KB Output is correct
71 Correct 0 ms 348 KB Output is correct
72 Correct 0 ms 348 KB Output is correct
73 Correct 28 ms 6328 KB Output is correct
74 Correct 135 ms 24132 KB Output is correct
75 Correct 105 ms 24144 KB Output is correct
76 Correct 111 ms 24040 KB Output is correct
77 Correct 105 ms 24148 KB Output is correct
78 Correct 0 ms 348 KB Output is correct
79 Correct 0 ms 348 KB Output is correct
80 Correct 3 ms 860 KB Output is correct
81 Correct 68 ms 14356 KB Output is correct
82 Correct 0 ms 348 KB Output is correct
83 Correct 1 ms 348 KB Output is correct
84 Correct 0 ms 348 KB Output is correct
85 Correct 31 ms 6324 KB Output is correct
86 Correct 49 ms 14316 KB Output is correct
87 Correct 52 ms 14164 KB Output is correct
88 Correct 52 ms 14164 KB Output is correct
89 Correct 47 ms 14164 KB Output is correct
90 Correct 0 ms 344 KB Output is correct
91 Correct 0 ms 348 KB Output is correct
92 Correct 2 ms 860 KB Output is correct
93 Correct 43 ms 14256 KB Output is correct
94 Correct 0 ms 344 KB Output is correct
95 Correct 0 ms 348 KB Output is correct
96 Correct 0 ms 348 KB Output is correct
97 Correct 10 ms 3932 KB Output is correct
98 Correct 41 ms 14260 KB Output is correct
99 Correct 43 ms 14164 KB Output is correct
100 Correct 41 ms 14048 KB Output is correct
101 Correct 48 ms 14420 KB Output is correct
102 Correct 41 ms 14164 KB Output is correct
103 Correct 40 ms 14136 KB Output is correct
104 Correct 43 ms 14164 KB Output is correct
105 Correct 48 ms 14164 KB Output is correct