Submission #613724

# Submission time Handle Problem Language Result Execution time Memory
613724 2022-07-30T09:49:01 Z Koosha_mv Connecting Supertrees (IOI20_supertrees) C++14
100 / 100
223 ms 34224 KB
#include "supertrees.h"
#include <bits/stdc++.h>
using namespace std;
#define dbgv(v) cout<<#v<<" = "; f(i,0,int(v.size())) cout<<v[i]<<" "; cout<<endl
#define dbga(a,x,y) cout<<#a<<" = "; f(i,x,y) cout<<a[i]<<" "; cout<<endl
#define erorp(x) cout<<#x<<"={"<<x.F<<" , "<<x.S<<"}"<<endl
#define eror(x) cout<<#x<<'='<<(x)<<endl
#define f_(i,a,b) for(int i=a;i>=b;i--)
#define f(i,a,b) for(int i=a;i<b;i++)
#define nb(x) __builtin_popcount(x)
#define all(v) v.begin(),v.end()
#define bit(n,k) (((n)>>(k))&1)
#define Add(x,y) x=(x+y)%mod
#define maxm(a,b) a=max(a,b)
#define minm(a,b) a=min(a,b)
#define lst(x) x[x.size()-1]
#define sz(x) int(x.size())
#define mp make_pair
#define ll long long
#define pb push_back
#define S second
#define F first

const int N=1010;

int n,cnt,valid=1,vis[N],ted[N],cmp[N],p[N][N];
vector<int> vec,g[N];
vector<vector<int>> ans;

void add_edge(int u,int v){
	//cout<<u<<" -> "<<v<<endl;
	ans[u][v]=1;
	ans[v][u]=1;
}
int calc(int u,int x){
	int res=0;
	f(i,0,n) res+=(p[u][i]==x);
	return res;
}
void dfs1(int u){
	vis[u]=1,cnt++;
	ted[cmp[u]]++;
	for(auto v : g[u]){
		if(vis[v]) continue ;
		cmp[v]=cmp[u];
		dfs1(v);
		add_edge(cmp[u],v);
		if(calc(v,1)!=calc(u,1)) valid=0;
	}

}
void dfs2(int u){
	vis[u]=2;
	cnt+=ted[u];
	vec.pb(u);
	for(auto v : g[u]){
		if(vis[v]) continue ;
		dfs2(v);
	}
}
int construct(vector<vector<int>> _p) {
	n=_p.size(),ans=_p;
	f(i,0,n) f(j,0,n){
		ans[i][j]=0;
		p[i][j]=_p[i][j];
		if(p[i][j]>2) valid=0;
	}
	f(i,0,n) f(j,0,n){
		if(p[i][j]==1){
			g[i].pb(j);
			g[j].pb(i);
		}
	}
	f(i,0,n){
		if(vis[i]) continue ;
		cnt=0;
		cmp[i]=i;
		dfs1(i);
		if(calc(i,1)!=cnt) valid=0;
	}
	f(i,0,n) vis[i]=0,g[i].clear();
	f(i,0,n) f(j,0,n){
		if(p[i][j]==2){
			g[cmp[i]].pb(cmp[j]);
			g[cmp[j]].pb(cmp[i]);
		}
	}
	f(i,0,n){
		if(cmp[i]!=i || vis[i]) continue ;
		vec.clear(),cnt=0;
		dfs2(i);
		if(vec.size()>1){
			f(j,0,int(vec.size())){
				add_edge(vec[j],(j+1==int(vec.size()) ? vec[0] : vec[j+1]));
			}
		}
		if(vec.size()==2){
			valid=0;
		}
		f(u,0,n){
			if(vis[cmp[u]]==2){ 
				if(calc(u,1)+calc(u,2)!=cnt){
					valid=0;
				}
			}
		}
		f(u,0,n){
			if(vis[u]==2){
				vis[u]=1;
			}
		}
	}
	if(valid==0) return 0;
	build(ans);
	return 1;
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 0 ms 340 KB Output is correct
4 Correct 0 ms 340 KB Output is correct
5 Correct 0 ms 340 KB Output is correct
6 Correct 8 ms 2464 KB Output is correct
7 Correct 184 ms 34224 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 0 ms 340 KB Output is correct
4 Correct 0 ms 340 KB Output is correct
5 Correct 0 ms 340 KB Output is correct
6 Correct 8 ms 2464 KB Output is correct
7 Correct 184 ms 34224 KB Output is correct
8 Correct 0 ms 340 KB Output is correct
9 Correct 0 ms 340 KB Output is correct
10 Correct 0 ms 340 KB Output is correct
11 Correct 0 ms 340 KB Output is correct
12 Correct 8 ms 2004 KB Output is correct
13 Correct 171 ms 26048 KB Output is correct
14 Correct 0 ms 340 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 4 ms 1748 KB Output is correct
17 Correct 94 ms 21916 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
20 Correct 45 ms 7848 KB Output is correct
21 Correct 179 ms 27088 KB Output is correct
22 Correct 173 ms 26044 KB Output is correct
23 Correct 213 ms 30120 KB Output is correct
24 Correct 188 ms 26072 KB Output is correct
25 Correct 74 ms 17180 KB Output is correct
26 Correct 74 ms 16048 KB Output is correct
27 Correct 187 ms 32292 KB Output is correct
28 Correct 194 ms 26008 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 0 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 0 ms 340 KB Output is correct
6 Correct 0 ms 340 KB Output is correct
7 Correct 0 ms 340 KB Output is correct
8 Correct 9 ms 2020 KB Output is correct
9 Correct 173 ms 26000 KB Output is correct
10 Correct 0 ms 340 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 10 ms 2388 KB Output is correct
13 Correct 189 ms 34196 KB Output is correct
14 Correct 0 ms 340 KB Output is correct
15 Correct 0 ms 340 KB Output is correct
16 Correct 4 ms 1748 KB Output is correct
17 Correct 98 ms 21792 KB Output is correct
18 Correct 0 ms 340 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
20 Correct 1 ms 384 KB Output is correct
21 Correct 47 ms 8368 KB Output is correct
22 Correct 174 ms 29004 KB Output is correct
23 Correct 184 ms 28108 KB Output is correct
24 Correct 183 ms 34124 KB Output is correct
25 Correct 74 ms 18084 KB Output is correct
26 Correct 91 ms 19096 KB Output is correct
27 Correct 169 ms 28076 KB Output is correct
28 Correct 183 ms 32128 KB Output is correct
29 Correct 85 ms 18200 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 0 ms 340 KB Output is correct
4 Correct 44 ms 8388 KB Output is correct
5 Correct 169 ms 29088 KB Output is correct
6 Correct 177 ms 28028 KB Output is correct
7 Correct 183 ms 32120 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 50 ms 8328 KB Output is correct
10 Correct 187 ms 29012 KB Output is correct
11 Correct 171 ms 28056 KB Output is correct
12 Correct 223 ms 34196 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 43 ms 8268 KB Output is correct
17 Correct 170 ms 29076 KB Output is correct
18 Correct 177 ms 29168 KB Output is correct
19 Correct 174 ms 28360 KB Output is correct
20 Correct 174 ms 28044 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 0 ms 340 KB Output is correct
4 Correct 0 ms 340 KB Output is correct
5 Correct 0 ms 340 KB Output is correct
6 Correct 8 ms 2464 KB Output is correct
7 Correct 184 ms 34224 KB Output is correct
8 Correct 0 ms 340 KB Output is correct
9 Correct 0 ms 340 KB Output is correct
10 Correct 0 ms 340 KB Output is correct
11 Correct 0 ms 340 KB Output is correct
12 Correct 8 ms 2004 KB Output is correct
13 Correct 171 ms 26048 KB Output is correct
14 Correct 0 ms 340 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 4 ms 1748 KB Output is correct
17 Correct 94 ms 21916 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
20 Correct 45 ms 7848 KB Output is correct
21 Correct 179 ms 27088 KB Output is correct
22 Correct 173 ms 26044 KB Output is correct
23 Correct 213 ms 30120 KB Output is correct
24 Correct 188 ms 26072 KB Output is correct
25 Correct 74 ms 17180 KB Output is correct
26 Correct 74 ms 16048 KB Output is correct
27 Correct 187 ms 32292 KB Output is correct
28 Correct 194 ms 26008 KB Output is correct
29 Correct 0 ms 340 KB Output is correct
30 Correct 0 ms 340 KB Output is correct
31 Correct 0 ms 340 KB Output is correct
32 Correct 1 ms 340 KB Output is correct
33 Correct 0 ms 340 KB Output is correct
34 Correct 0 ms 340 KB Output is correct
35 Correct 0 ms 340 KB Output is correct
36 Correct 9 ms 2020 KB Output is correct
37 Correct 173 ms 26000 KB Output is correct
38 Correct 0 ms 340 KB Output is correct
39 Correct 1 ms 340 KB Output is correct
40 Correct 10 ms 2388 KB Output is correct
41 Correct 189 ms 34196 KB Output is correct
42 Correct 0 ms 340 KB Output is correct
43 Correct 0 ms 340 KB Output is correct
44 Correct 4 ms 1748 KB Output is correct
45 Correct 98 ms 21792 KB Output is correct
46 Correct 0 ms 340 KB Output is correct
47 Correct 1 ms 340 KB Output is correct
48 Correct 1 ms 384 KB Output is correct
49 Correct 47 ms 8368 KB Output is correct
50 Correct 174 ms 29004 KB Output is correct
51 Correct 184 ms 28108 KB Output is correct
52 Correct 183 ms 34124 KB Output is correct
53 Correct 74 ms 18084 KB Output is correct
54 Correct 91 ms 19096 KB Output is correct
55 Correct 169 ms 28076 KB Output is correct
56 Correct 183 ms 32128 KB Output is correct
57 Correct 85 ms 18200 KB Output is correct
58 Correct 1 ms 340 KB Output is correct
59 Correct 1 ms 332 KB Output is correct
60 Correct 5 ms 2132 KB Output is correct
61 Correct 101 ms 26764 KB Output is correct
62 Correct 1 ms 340 KB Output is correct
63 Correct 1 ms 340 KB Output is correct
64 Correct 1 ms 340 KB Output is correct
65 Correct 44 ms 8244 KB Output is correct
66 Correct 89 ms 19348 KB Output is correct
67 Correct 112 ms 19148 KB Output is correct
68 Correct 76 ms 18504 KB Output is correct
69 Correct 72 ms 18076 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 0 ms 340 KB Output is correct
4 Correct 0 ms 340 KB Output is correct
5 Correct 0 ms 340 KB Output is correct
6 Correct 8 ms 2464 KB Output is correct
7 Correct 184 ms 34224 KB Output is correct
8 Correct 0 ms 340 KB Output is correct
9 Correct 0 ms 340 KB Output is correct
10 Correct 0 ms 340 KB Output is correct
11 Correct 0 ms 340 KB Output is correct
12 Correct 8 ms 2004 KB Output is correct
13 Correct 171 ms 26048 KB Output is correct
14 Correct 0 ms 340 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 4 ms 1748 KB Output is correct
17 Correct 94 ms 21916 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
20 Correct 45 ms 7848 KB Output is correct
21 Correct 179 ms 27088 KB Output is correct
22 Correct 173 ms 26044 KB Output is correct
23 Correct 213 ms 30120 KB Output is correct
24 Correct 188 ms 26072 KB Output is correct
25 Correct 74 ms 17180 KB Output is correct
26 Correct 74 ms 16048 KB Output is correct
27 Correct 187 ms 32292 KB Output is correct
28 Correct 194 ms 26008 KB Output is correct
29 Correct 0 ms 340 KB Output is correct
30 Correct 0 ms 340 KB Output is correct
31 Correct 0 ms 340 KB Output is correct
32 Correct 1 ms 340 KB Output is correct
33 Correct 0 ms 340 KB Output is correct
34 Correct 0 ms 340 KB Output is correct
35 Correct 0 ms 340 KB Output is correct
36 Correct 9 ms 2020 KB Output is correct
37 Correct 173 ms 26000 KB Output is correct
38 Correct 0 ms 340 KB Output is correct
39 Correct 1 ms 340 KB Output is correct
40 Correct 10 ms 2388 KB Output is correct
41 Correct 189 ms 34196 KB Output is correct
42 Correct 0 ms 340 KB Output is correct
43 Correct 0 ms 340 KB Output is correct
44 Correct 4 ms 1748 KB Output is correct
45 Correct 98 ms 21792 KB Output is correct
46 Correct 0 ms 340 KB Output is correct
47 Correct 1 ms 340 KB Output is correct
48 Correct 1 ms 384 KB Output is correct
49 Correct 47 ms 8368 KB Output is correct
50 Correct 174 ms 29004 KB Output is correct
51 Correct 184 ms 28108 KB Output is correct
52 Correct 183 ms 34124 KB Output is correct
53 Correct 74 ms 18084 KB Output is correct
54 Correct 91 ms 19096 KB Output is correct
55 Correct 169 ms 28076 KB Output is correct
56 Correct 183 ms 32128 KB Output is correct
57 Correct 85 ms 18200 KB Output is correct
58 Correct 0 ms 340 KB Output is correct
59 Correct 0 ms 340 KB Output is correct
60 Correct 0 ms 340 KB Output is correct
61 Correct 44 ms 8388 KB Output is correct
62 Correct 169 ms 29088 KB Output is correct
63 Correct 177 ms 28028 KB Output is correct
64 Correct 183 ms 32120 KB Output is correct
65 Correct 1 ms 340 KB Output is correct
66 Correct 50 ms 8328 KB Output is correct
67 Correct 187 ms 29012 KB Output is correct
68 Correct 171 ms 28056 KB Output is correct
69 Correct 223 ms 34196 KB Output is correct
70 Correct 1 ms 340 KB Output is correct
71 Correct 1 ms 340 KB Output is correct
72 Correct 1 ms 340 KB Output is correct
73 Correct 43 ms 8268 KB Output is correct
74 Correct 170 ms 29076 KB Output is correct
75 Correct 177 ms 29168 KB Output is correct
76 Correct 174 ms 28360 KB Output is correct
77 Correct 174 ms 28044 KB Output is correct
78 Correct 1 ms 340 KB Output is correct
79 Correct 1 ms 332 KB Output is correct
80 Correct 5 ms 2132 KB Output is correct
81 Correct 101 ms 26764 KB Output is correct
82 Correct 1 ms 340 KB Output is correct
83 Correct 1 ms 340 KB Output is correct
84 Correct 1 ms 340 KB Output is correct
85 Correct 44 ms 8244 KB Output is correct
86 Correct 89 ms 19348 KB Output is correct
87 Correct 112 ms 19148 KB Output is correct
88 Correct 76 ms 18504 KB Output is correct
89 Correct 72 ms 18076 KB Output is correct
90 Correct 1 ms 340 KB Output is correct
91 Correct 1 ms 340 KB Output is correct
92 Correct 5 ms 2004 KB Output is correct
93 Correct 94 ms 23456 KB Output is correct
94 Correct 0 ms 340 KB Output is correct
95 Correct 0 ms 340 KB Output is correct
96 Correct 1 ms 340 KB Output is correct
97 Correct 19 ms 5788 KB Output is correct
98 Correct 76 ms 19104 KB Output is correct
99 Correct 76 ms 19224 KB Output is correct
100 Correct 86 ms 18452 KB Output is correct
101 Correct 74 ms 18076 KB Output is correct
102 Correct 77 ms 17992 KB Output is correct
103 Correct 99 ms 23824 KB Output is correct
104 Correct 89 ms 23952 KB Output is correct
105 Correct 88 ms 18072 KB Output is correct