Submission #395174

# Submission time Handle Problem Language Result Execution time Memory
395174 2021-04-28T00:08:04 Z AmineWeslati Connecting Supertrees (IOI20_supertrees) C++14
100 / 100
312 ms 38216 KB
#include "supertrees.h"
#include "bits/stdc++.h"
using namespace std;

typedef long long ll;
typedef vector<int> vi;
#define FOR(i,a,b) for(int i=a; i<b; i++)
#define ROF(i,a,b) for(int i=b-1; i>=a; i--)
#define sz(a) (int)a.size()
#define pb push_back

//-----------------------------------------------------//

#define line linee
const int MX=2000+10;
int N,p[MX][MX]; 
vi adj[MX];

vi vec,vis(MX,0);
void dfs(int u){
	vis[u]=1;
	vec.pb(u);
	for(int v: adj[u]) if(!vis[v]) dfs(v);
}

vi line[MX];
vi vis2(MX,0),vec2,linev(MX,0);

void dfs2(int u){
	vis2[u]=1;
	vec2.pb(u);
	for(int v: line[u]) if(!vis2[v]) dfs2(v);
}

int construct(vector<vi> p) {
	N=sz(p);
	FOR(i,0,N) FOR(j,i+1,N){
		::p[i][j]=p[i][j];
		if(p[i][j]==3) return 0;
		if(p[i][j]>0){
			adj[i].pb(j);
			adj[j].pb(i);
		}
	}

	vector<vi>ans(N,vi(N,0));
	FOR(node,0,N) if(!vis[node]){
		vec.clear();
		dfs(node);
			
		int n=sz(vec);
		FOR(i,0,n) FOR(j,i+1,n){
			int u=vec[i],v=vec[j];
			if(p[u][v]==0) return 0;
			if(p[u][v]==1){
				line[u].pb(v);
				line[v].pb(u);
			}
		}  

		vi cy;
		for(int idx: vec) if(!vis2[idx]){
			vec2.clear();
			dfs2(idx);

			//for(int u: vec2) cout << u << ' '; cout << endl;

			for(int u: vec2) linev[u]=1;

			for(int u: vec2){
				for(int v: vec){
					if(linev[v] && p[u][v]!=1) return -1;
					if(!linev[v] && p[u][v]!=2) return -1;
				}
			}

			FOR(i,0,sz(vec2)-1){
				int u=vec2[i],v=vec2[i+1];
				ans[u][v]=ans[v][u]=1;
			}
			cy.pb(vec2[0]);

			for(int u: vec2) linev[u]=0;
		}

		if(sz(cy)==2) return 0;

		if(sz(cy)>2){
			FOR(i,0,sz(cy)){
				int u=cy[i],v=cy[(i+1)%sz(cy)]; 
				ans[u][v]=ans[v][u]=1;
			}
		}
		
		
	}

	build(ans);

	return 1;
}


/*
4
1 1 2 2
1 1 2 2
2 2 1 2
2 2 2 1
*/

/*
4
1 1 1 1
1 1 1 1
1 1 1 1
1 1 1 1
*/
# Verdict Execution time Memory Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 1 ms 424 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 12 ms 2712 KB Output is correct
7 Correct 290 ms 38216 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 1 ms 424 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 12 ms 2712 KB Output is correct
7 Correct 290 ms 38216 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 1 ms 332 KB Output is correct
10 Correct 1 ms 332 KB Output is correct
11 Correct 1 ms 460 KB Output is correct
12 Correct 11 ms 2252 KB Output is correct
13 Correct 285 ms 30000 KB Output is correct
14 Correct 1 ms 332 KB Output is correct
15 Correct 1 ms 332 KB Output is correct
16 Correct 6 ms 1996 KB Output is correct
17 Correct 143 ms 23024 KB Output is correct
18 Correct 1 ms 428 KB Output is correct
19 Correct 1 ms 332 KB Output is correct
20 Correct 65 ms 8900 KB Output is correct
21 Correct 257 ms 31104 KB Output is correct
22 Correct 275 ms 30080 KB Output is correct
23 Correct 273 ms 34260 KB Output is correct
24 Correct 265 ms 30028 KB Output is correct
25 Correct 122 ms 20968 KB Output is correct
26 Correct 114 ms 20216 KB Output is correct
27 Correct 272 ms 36260 KB Output is correct
28 Correct 264 ms 29980 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 1 ms 424 KB Output is correct
8 Correct 12 ms 2252 KB Output is correct
9 Correct 262 ms 30180 KB Output is correct
10 Correct 1 ms 332 KB Output is correct
11 Correct 1 ms 460 KB Output is correct
12 Correct 12 ms 2452 KB Output is correct
13 Correct 267 ms 34200 KB Output is correct
14 Correct 1 ms 332 KB Output is correct
15 Correct 1 ms 460 KB Output is correct
16 Correct 6 ms 1940 KB Output is correct
17 Correct 131 ms 22892 KB Output is correct
18 Correct 1 ms 424 KB Output is correct
19 Correct 1 ms 332 KB Output is correct
20 Correct 1 ms 332 KB Output is correct
21 Correct 64 ms 8932 KB Output is correct
22 Correct 262 ms 30700 KB Output is correct
23 Correct 256 ms 30020 KB Output is correct
24 Correct 271 ms 33148 KB Output is correct
25 Correct 115 ms 20164 KB Output is correct
26 Correct 119 ms 20724 KB Output is correct
27 Correct 256 ms 30080 KB Output is correct
28 Correct 312 ms 32048 KB Output is correct
29 Correct 115 ms 20080 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 1 ms 420 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 66 ms 8944 KB Output is correct
5 Correct 260 ms 31228 KB Output is correct
6 Correct 257 ms 30148 KB Output is correct
7 Correct 280 ms 34116 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 67 ms 8812 KB Output is correct
10 Correct 264 ms 30524 KB Output is correct
11 Correct 258 ms 30128 KB Output is correct
12 Correct 269 ms 33348 KB Output is correct
13 Correct 1 ms 332 KB Output is correct
14 Correct 1 ms 332 KB Output is correct
15 Correct 1 ms 460 KB Output is correct
16 Correct 63 ms 8900 KB Output is correct
17 Correct 256 ms 30660 KB Output is correct
18 Correct 257 ms 30528 KB Output is correct
19 Correct 259 ms 30276 KB Output is correct
20 Correct 256 ms 30064 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 1 ms 424 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 12 ms 2712 KB Output is correct
7 Correct 290 ms 38216 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 1 ms 332 KB Output is correct
10 Correct 1 ms 332 KB Output is correct
11 Correct 1 ms 460 KB Output is correct
12 Correct 11 ms 2252 KB Output is correct
13 Correct 285 ms 30000 KB Output is correct
14 Correct 1 ms 332 KB Output is correct
15 Correct 1 ms 332 KB Output is correct
16 Correct 6 ms 1996 KB Output is correct
17 Correct 143 ms 23024 KB Output is correct
18 Correct 1 ms 428 KB Output is correct
19 Correct 1 ms 332 KB Output is correct
20 Correct 65 ms 8900 KB Output is correct
21 Correct 257 ms 31104 KB Output is correct
22 Correct 275 ms 30080 KB Output is correct
23 Correct 273 ms 34260 KB Output is correct
24 Correct 265 ms 30028 KB Output is correct
25 Correct 122 ms 20968 KB Output is correct
26 Correct 114 ms 20216 KB Output is correct
27 Correct 272 ms 36260 KB Output is correct
28 Correct 264 ms 29980 KB Output is correct
29 Correct 1 ms 332 KB Output is correct
30 Correct 1 ms 332 KB Output is correct
31 Correct 1 ms 332 KB Output is correct
32 Correct 1 ms 332 KB Output is correct
33 Correct 1 ms 332 KB Output is correct
34 Correct 1 ms 332 KB Output is correct
35 Correct 1 ms 424 KB Output is correct
36 Correct 12 ms 2252 KB Output is correct
37 Correct 262 ms 30180 KB Output is correct
38 Correct 1 ms 332 KB Output is correct
39 Correct 1 ms 460 KB Output is correct
40 Correct 12 ms 2452 KB Output is correct
41 Correct 267 ms 34200 KB Output is correct
42 Correct 1 ms 332 KB Output is correct
43 Correct 1 ms 460 KB Output is correct
44 Correct 6 ms 1940 KB Output is correct
45 Correct 131 ms 22892 KB Output is correct
46 Correct 1 ms 424 KB Output is correct
47 Correct 1 ms 332 KB Output is correct
48 Correct 1 ms 332 KB Output is correct
49 Correct 64 ms 8932 KB Output is correct
50 Correct 262 ms 30700 KB Output is correct
51 Correct 256 ms 30020 KB Output is correct
52 Correct 271 ms 33148 KB Output is correct
53 Correct 115 ms 20164 KB Output is correct
54 Correct 119 ms 20724 KB Output is correct
55 Correct 256 ms 30080 KB Output is correct
56 Correct 312 ms 32048 KB Output is correct
57 Correct 115 ms 20080 KB Output is correct
58 Correct 1 ms 332 KB Output is correct
59 Correct 1 ms 424 KB Output is correct
60 Correct 8 ms 1996 KB Output is correct
61 Correct 131 ms 24560 KB Output is correct
62 Correct 1 ms 332 KB Output is correct
63 Correct 1 ms 460 KB Output is correct
64 Correct 1 ms 332 KB Output is correct
65 Correct 64 ms 8900 KB Output is correct
66 Correct 118 ms 20716 KB Output is correct
67 Correct 118 ms 20676 KB Output is correct
68 Correct 116 ms 20292 KB Output is correct
69 Correct 116 ms 20080 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 1 ms 424 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 12 ms 2712 KB Output is correct
7 Correct 290 ms 38216 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 1 ms 332 KB Output is correct
10 Correct 1 ms 332 KB Output is correct
11 Correct 1 ms 460 KB Output is correct
12 Correct 11 ms 2252 KB Output is correct
13 Correct 285 ms 30000 KB Output is correct
14 Correct 1 ms 332 KB Output is correct
15 Correct 1 ms 332 KB Output is correct
16 Correct 6 ms 1996 KB Output is correct
17 Correct 143 ms 23024 KB Output is correct
18 Correct 1 ms 428 KB Output is correct
19 Correct 1 ms 332 KB Output is correct
20 Correct 65 ms 8900 KB Output is correct
21 Correct 257 ms 31104 KB Output is correct
22 Correct 275 ms 30080 KB Output is correct
23 Correct 273 ms 34260 KB Output is correct
24 Correct 265 ms 30028 KB Output is correct
25 Correct 122 ms 20968 KB Output is correct
26 Correct 114 ms 20216 KB Output is correct
27 Correct 272 ms 36260 KB Output is correct
28 Correct 264 ms 29980 KB Output is correct
29 Correct 1 ms 332 KB Output is correct
30 Correct 1 ms 332 KB Output is correct
31 Correct 1 ms 332 KB Output is correct
32 Correct 1 ms 332 KB Output is correct
33 Correct 1 ms 332 KB Output is correct
34 Correct 1 ms 332 KB Output is correct
35 Correct 1 ms 424 KB Output is correct
36 Correct 12 ms 2252 KB Output is correct
37 Correct 262 ms 30180 KB Output is correct
38 Correct 1 ms 332 KB Output is correct
39 Correct 1 ms 460 KB Output is correct
40 Correct 12 ms 2452 KB Output is correct
41 Correct 267 ms 34200 KB Output is correct
42 Correct 1 ms 332 KB Output is correct
43 Correct 1 ms 460 KB Output is correct
44 Correct 6 ms 1940 KB Output is correct
45 Correct 131 ms 22892 KB Output is correct
46 Correct 1 ms 424 KB Output is correct
47 Correct 1 ms 332 KB Output is correct
48 Correct 1 ms 332 KB Output is correct
49 Correct 64 ms 8932 KB Output is correct
50 Correct 262 ms 30700 KB Output is correct
51 Correct 256 ms 30020 KB Output is correct
52 Correct 271 ms 33148 KB Output is correct
53 Correct 115 ms 20164 KB Output is correct
54 Correct 119 ms 20724 KB Output is correct
55 Correct 256 ms 30080 KB Output is correct
56 Correct 312 ms 32048 KB Output is correct
57 Correct 115 ms 20080 KB Output is correct
58 Correct 1 ms 332 KB Output is correct
59 Correct 1 ms 420 KB Output is correct
60 Correct 1 ms 332 KB Output is correct
61 Correct 66 ms 8944 KB Output is correct
62 Correct 260 ms 31228 KB Output is correct
63 Correct 257 ms 30148 KB Output is correct
64 Correct 280 ms 34116 KB Output is correct
65 Correct 1 ms 332 KB Output is correct
66 Correct 67 ms 8812 KB Output is correct
67 Correct 264 ms 30524 KB Output is correct
68 Correct 258 ms 30128 KB Output is correct
69 Correct 269 ms 33348 KB Output is correct
70 Correct 1 ms 332 KB Output is correct
71 Correct 1 ms 332 KB Output is correct
72 Correct 1 ms 460 KB Output is correct
73 Correct 63 ms 8900 KB Output is correct
74 Correct 256 ms 30660 KB Output is correct
75 Correct 257 ms 30528 KB Output is correct
76 Correct 259 ms 30276 KB Output is correct
77 Correct 256 ms 30064 KB Output is correct
78 Correct 1 ms 332 KB Output is correct
79 Correct 1 ms 424 KB Output is correct
80 Correct 8 ms 1996 KB Output is correct
81 Correct 131 ms 24560 KB Output is correct
82 Correct 1 ms 332 KB Output is correct
83 Correct 1 ms 460 KB Output is correct
84 Correct 1 ms 332 KB Output is correct
85 Correct 64 ms 8900 KB Output is correct
86 Correct 118 ms 20716 KB Output is correct
87 Correct 118 ms 20676 KB Output is correct
88 Correct 116 ms 20292 KB Output is correct
89 Correct 116 ms 20080 KB Output is correct
90 Correct 1 ms 332 KB Output is correct
91 Correct 1 ms 332 KB Output is correct
92 Correct 6 ms 760 KB Output is correct
93 Correct 110 ms 10148 KB Output is correct
94 Correct 1 ms 332 KB Output is correct
95 Correct 1 ms 332 KB Output is correct
96 Correct 1 ms 332 KB Output is correct
97 Correct 28 ms 3060 KB Output is correct
98 Correct 116 ms 10744 KB Output is correct
99 Correct 118 ms 11512 KB Output is correct
100 Correct 109 ms 10820 KB Output is correct
101 Correct 111 ms 12652 KB Output is correct
102 Correct 109 ms 10228 KB Output is correct
103 Correct 109 ms 10220 KB Output is correct
104 Correct 109 ms 10236 KB Output is correct
105 Correct 113 ms 10224 KB Output is correct