Submission #927621

# Submission time Handle Problem Language Result Execution time Memory
927621 2024-02-15T07:34:19 Z MrDeboo Connecting Supertrees (IOI20_supertrees) C++17
100 / 100
172 ms 30392 KB
#include "bits/stdc++.h"
#include "supertrees.h"
using namespace std;
vector<int>vct[1000][2];
vector<vector<int>>ans;
vector<vector<int>>P;
int slv(vector<int>v){
	for(auto &i:v){
		for(auto &w:v){
			if(!P[i][w])return 0;
		}
	}
	vector<int>V;
	vector<bool>vis(P.size());
	for(int i=0;i<v.size();i++){
		if(vis[i])continue;
		int I=i;
		for(int w=0;w<v.size();w++){
			if(P[v[i]][v[w]]==1&&!vis[w]&&i!=w){
				bool bl=1;
				for(int j=0;j<v.size();j++){
					if(j==i||j==w)continue;
					if(P[v[j]][v[i]]!=P[v[j]][v[w]])bl=0;
				}
				if(bl){
					vis[w]=1;
					ans[v[I]][v[w]]=1;
					ans[v[w]][v[I]]=1;
					I=w;
				}
			}
		}
		V.push_back(v[i]);
		vis[i]=1;
	}
	v=V;
	for(int i=0;i<v.size();i++){
		for(int w=i+1;w<v.size();w++){
			if(P[v[i]][v[w]]!=2)return 0;
		}
	}
	if(v.size()>1){
		if(v.size()==2)return 0;
		for(int i=0;i<v.size();i++){
			ans[v[i]][v[(i+1)%v.size()]]=1;
			ans[v[(i+1)%v.size()]][v[i]]=1;
		}
	}
	return 1;
}
int construct(std::vector<std::vector<int>> p){
	for(auto &i:p){
		for(auto &w:i){
			if(w>2)return 0;
		}
	}
	for(auto &i:p)P.push_back(i);
	int n=p.size();
	for(int i=0;i<n;i++){
		for(int w=0;w<n;w++){
			if(i==w)continue;
			if(p[i][w])vct[i][p[i][w]-1].push_back(w);
		}
	}
	for(int i=0;i<n;i++){
		vector<int>v(n);
		ans.push_back(v);
	}
	vector<bool>vis(n);
	for(int i=0;i<n;i++){
		for(int w=0;w<n;w++){
			if(vis[i]||vis[w]||i==w)continue;
			if(p[i][w]){
				deque<int>dq={i};
				vis[i]=1;
				vector<int>vc;
				while(dq.size()){
					int a=dq.front();
					vc.push_back(a);
					dq.pop_front();
					for(auto &j:vct[a][1]){
						if(!vis[j]){
							vis[j]=1;
							dq.push_back(j);
						}
					}
					for(auto &j:vct[a][0]){
						if(!vis[j]){
							vis[j]=1;
							dq.push_back(j);
						}
					}
				}
				if(!slv(vc))return 0;
			}
		}
	}
	build(ans);
	return 1;
}

Compilation message

supertrees.cpp: In function 'int slv(std::vector<int>)':
supertrees.cpp:15:15: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   15 |  for(int i=0;i<v.size();i++){
      |              ~^~~~~~~~~
supertrees.cpp:18:16: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   18 |   for(int w=0;w<v.size();w++){
      |               ~^~~~~~~~~
supertrees.cpp:21:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   21 |     for(int j=0;j<v.size();j++){
      |                 ~^~~~~~~~~
supertrees.cpp:37:15: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   37 |  for(int i=0;i<v.size();i++){
      |              ~^~~~~~~~~
supertrees.cpp:38:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   38 |   for(int w=i+1;w<v.size();w++){
      |                 ~^~~~~~~~~
supertrees.cpp:44:16: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   44 |   for(int i=0;i<v.size();i++){
      |               ~^~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 1 ms 504 KB Output is correct
3 Correct 1 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 7 ms 1628 KB Output is correct
7 Correct 157 ms 30012 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 1 ms 504 KB Output is correct
3 Correct 1 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 7 ms 1628 KB Output is correct
7 Correct 157 ms 30012 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 0 ms 348 KB Output is correct
12 Correct 7 ms 1372 KB Output is correct
13 Correct 153 ms 26168 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 1 ms 348 KB Output is correct
16 Correct 4 ms 1116 KB Output is correct
17 Correct 73 ms 18492 KB Output is correct
18 Correct 1 ms 344 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 39 ms 7004 KB Output is correct
21 Correct 158 ms 26512 KB Output is correct
22 Correct 152 ms 26184 KB Output is correct
23 Correct 167 ms 28072 KB Output is correct
24 Correct 151 ms 26032 KB Output is correct
25 Correct 74 ms 16724 KB Output is correct
26 Correct 67 ms 16180 KB Output is correct
27 Correct 156 ms 29004 KB Output is correct
28 Correct 151 ms 26100 KB Output is correct
# Verdict Execution time Memory 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 0 ms 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 0 ms 376 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 6 ms 1372 KB Output is correct
9 Correct 151 ms 25976 KB Output is correct
10 Correct 0 ms 344 KB Output is correct
11 Correct 0 ms 344 KB Output is correct
12 Correct 7 ms 1628 KB Output is correct
13 Correct 158 ms 30036 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 4 ms 1116 KB Output is correct
17 Correct 84 ms 18488 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 38 ms 6740 KB Output is correct
22 Correct 158 ms 27964 KB Output is correct
23 Correct 158 ms 27700 KB Output is correct
24 Correct 172 ms 30292 KB Output is correct
25 Correct 71 ms 17492 KB Output is correct
26 Correct 71 ms 17980 KB Output is correct
27 Correct 150 ms 27472 KB Output is correct
28 Correct 162 ms 29436 KB Output is correct
29 Correct 72 ms 17704 KB Output is correct
# Verdict Execution time Memory 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 Correct 39 ms 6884 KB Output is correct
5 Correct 151 ms 26704 KB Output is correct
6 Correct 153 ms 26184 KB Output is correct
7 Correct 157 ms 28268 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 38 ms 6800 KB Output is correct
10 Correct 155 ms 27984 KB Output is correct
11 Correct 155 ms 27324 KB Output is correct
12 Correct 158 ms 30392 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 44 ms 7860 KB Output is correct
17 Correct 157 ms 27964 KB Output is correct
18 Correct 151 ms 27984 KB Output is correct
19 Correct 152 ms 27472 KB Output is correct
20 Correct 150 ms 27320 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 1 ms 504 KB Output is correct
3 Correct 1 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 7 ms 1628 KB Output is correct
7 Correct 157 ms 30012 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 0 ms 348 KB Output is correct
12 Correct 7 ms 1372 KB Output is correct
13 Correct 153 ms 26168 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 1 ms 348 KB Output is correct
16 Correct 4 ms 1116 KB Output is correct
17 Correct 73 ms 18492 KB Output is correct
18 Correct 1 ms 344 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 39 ms 7004 KB Output is correct
21 Correct 158 ms 26512 KB Output is correct
22 Correct 152 ms 26184 KB Output is correct
23 Correct 167 ms 28072 KB Output is correct
24 Correct 151 ms 26032 KB Output is correct
25 Correct 74 ms 16724 KB Output is correct
26 Correct 67 ms 16180 KB Output is correct
27 Correct 156 ms 29004 KB Output is correct
28 Correct 151 ms 26100 KB Output is correct
29 Correct 0 ms 348 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 1 ms 348 KB Output is correct
34 Correct 0 ms 376 KB Output is correct
35 Correct 0 ms 348 KB Output is correct
36 Correct 6 ms 1372 KB Output is correct
37 Correct 151 ms 25976 KB Output is correct
38 Correct 0 ms 344 KB Output is correct
39 Correct 0 ms 344 KB Output is correct
40 Correct 7 ms 1628 KB Output is correct
41 Correct 158 ms 30036 KB Output is correct
42 Correct 0 ms 348 KB Output is correct
43 Correct 0 ms 348 KB Output is correct
44 Correct 4 ms 1116 KB Output is correct
45 Correct 84 ms 18488 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 38 ms 6740 KB Output is correct
50 Correct 158 ms 27964 KB Output is correct
51 Correct 158 ms 27700 KB Output is correct
52 Correct 172 ms 30292 KB Output is correct
53 Correct 71 ms 17492 KB Output is correct
54 Correct 71 ms 17980 KB Output is correct
55 Correct 150 ms 27472 KB Output is correct
56 Correct 162 ms 29436 KB Output is correct
57 Correct 72 ms 17704 KB Output is correct
58 Correct 1 ms 348 KB Output is correct
59 Correct 0 ms 348 KB Output is correct
60 Correct 4 ms 1368 KB Output is correct
61 Correct 89 ms 21560 KB Output is correct
62 Correct 1 ms 344 KB Output is correct
63 Correct 0 ms 348 KB Output is correct
64 Correct 0 ms 348 KB Output is correct
65 Correct 38 ms 7252 KB Output is correct
66 Correct 73 ms 18000 KB Output is correct
67 Correct 71 ms 17972 KB Output is correct
68 Correct 68 ms 17592 KB Output is correct
69 Correct 66 ms 17332 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 1 ms 504 KB Output is correct
3 Correct 1 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 7 ms 1628 KB Output is correct
7 Correct 157 ms 30012 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 0 ms 348 KB Output is correct
12 Correct 7 ms 1372 KB Output is correct
13 Correct 153 ms 26168 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 1 ms 348 KB Output is correct
16 Correct 4 ms 1116 KB Output is correct
17 Correct 73 ms 18492 KB Output is correct
18 Correct 1 ms 344 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 39 ms 7004 KB Output is correct
21 Correct 158 ms 26512 KB Output is correct
22 Correct 152 ms 26184 KB Output is correct
23 Correct 167 ms 28072 KB Output is correct
24 Correct 151 ms 26032 KB Output is correct
25 Correct 74 ms 16724 KB Output is correct
26 Correct 67 ms 16180 KB Output is correct
27 Correct 156 ms 29004 KB Output is correct
28 Correct 151 ms 26100 KB Output is correct
29 Correct 0 ms 348 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 1 ms 348 KB Output is correct
34 Correct 0 ms 376 KB Output is correct
35 Correct 0 ms 348 KB Output is correct
36 Correct 6 ms 1372 KB Output is correct
37 Correct 151 ms 25976 KB Output is correct
38 Correct 0 ms 344 KB Output is correct
39 Correct 0 ms 344 KB Output is correct
40 Correct 7 ms 1628 KB Output is correct
41 Correct 158 ms 30036 KB Output is correct
42 Correct 0 ms 348 KB Output is correct
43 Correct 0 ms 348 KB Output is correct
44 Correct 4 ms 1116 KB Output is correct
45 Correct 84 ms 18488 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 38 ms 6740 KB Output is correct
50 Correct 158 ms 27964 KB Output is correct
51 Correct 158 ms 27700 KB Output is correct
52 Correct 172 ms 30292 KB Output is correct
53 Correct 71 ms 17492 KB Output is correct
54 Correct 71 ms 17980 KB Output is correct
55 Correct 150 ms 27472 KB Output is correct
56 Correct 162 ms 29436 KB Output is correct
57 Correct 72 ms 17704 KB Output is correct
58 Correct 1 ms 348 KB Output is correct
59 Correct 1 ms 348 KB Output is correct
60 Correct 0 ms 348 KB Output is correct
61 Correct 39 ms 6884 KB Output is correct
62 Correct 151 ms 26704 KB Output is correct
63 Correct 153 ms 26184 KB Output is correct
64 Correct 157 ms 28268 KB Output is correct
65 Correct 0 ms 348 KB Output is correct
66 Correct 38 ms 6800 KB Output is correct
67 Correct 155 ms 27984 KB Output is correct
68 Correct 155 ms 27324 KB Output is correct
69 Correct 158 ms 30392 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 44 ms 7860 KB Output is correct
74 Correct 157 ms 27964 KB Output is correct
75 Correct 151 ms 27984 KB Output is correct
76 Correct 152 ms 27472 KB Output is correct
77 Correct 150 ms 27320 KB Output is correct
78 Correct 1 ms 348 KB Output is correct
79 Correct 0 ms 348 KB Output is correct
80 Correct 4 ms 1368 KB Output is correct
81 Correct 89 ms 21560 KB Output is correct
82 Correct 1 ms 344 KB Output is correct
83 Correct 0 ms 348 KB Output is correct
84 Correct 0 ms 348 KB Output is correct
85 Correct 38 ms 7252 KB Output is correct
86 Correct 73 ms 18000 KB Output is correct
87 Correct 71 ms 17972 KB Output is correct
88 Correct 68 ms 17592 KB Output is correct
89 Correct 66 ms 17332 KB Output is correct
90 Correct 0 ms 344 KB Output is correct
91 Correct 0 ms 344 KB Output is correct
92 Correct 3 ms 856 KB Output is correct
93 Correct 67 ms 9624 KB Output is correct
94 Correct 0 ms 348 KB Output is correct
95 Correct 0 ms 348 KB Output is correct
96 Correct 0 ms 348 KB Output is correct
97 Correct 16 ms 2740 KB Output is correct
98 Correct 64 ms 9556 KB Output is correct
99 Correct 64 ms 9528 KB Output is correct
100 Correct 65 ms 9528 KB Output is correct
101 Correct 67 ms 9556 KB Output is correct
102 Correct 62 ms 9532 KB Output is correct
103 Correct 62 ms 9524 KB Output is correct
104 Correct 70 ms 9556 KB Output is correct
105 Correct 71 ms 9556 KB Output is correct