#include "supertrees.h"
#include "bits/stdc++.h"
using namespace std;
typedef pair<int,int> pii;
const int MAXN=1005;
int par[MAXN];
bool idx[MAXN];
vector<int> kel[MAXN];
int find(int x){
if(par[x]==x)return par[x];
return par[x]=find(par[x]);
}
void join(int a,int b){
int ortua=find(a),ortub=find(b);
par[ortua]=ortub;
}
int construct(vector<vector<int>> p){
vector<pii> nol;
vector<vector<int>> ans;
int n = p.size();
for(int i=0;i<n;i++)par[i]=i;
ans.resize(n);
for(int i=0;i<n;i++){
ans[i].resize(n);
for(int j=0;j<n;j++){
ans[i][j]=0;
if(i==j)continue;
if(p[i][j])join(i,j);
else if(i<j)nol.push_back({i,j});
}
}
for(auto isi : nol){
if(find(isi.first)==find(isi.second))return 0;
}
for(int i=0;i<n;i++)kel[find(i)].push_back(i);
for(int i=0;i<n;i++){
if(kel[i].size()<=1)continue;
vector<int> satu,dua;
for(int j=0;j<kel[i].size();j++){
bool ada=false;
for(int k=0;k<kel[i].size();k++){
if(j==k)continue;
if(p[kel[i][j]][kel[i][k]]==1){
satu.push_back(kel[i][k]);
ada=true;
}
}
if(ada){
satu.push_back(kel[i][j]);
break;
}
}
for(auto isi : satu)idx[isi]=true;
for(int j=0;j<satu.size();j++){
for(int k=0;k<kel[i].size();k++){
if(satu[j]==kel[i][k])continue;
if(p[satu[j]][kel[i][k]]==1){
if(!idx[kel[i][k]])return 0;
}
}
}
for(auto isi : kel[i]){
if(!idx[isi])dua.push_back(isi);
}
if(!satu.empty()){
dua.push_back(satu.back());
satu.pop_back();
}
if(dua.size()==2)return 0;
for(int i=0;i<dua.size();i++){
for(int j=0;j<dua.size();j++){
if(i==j)continue;
if(p[dua[i]][dua[j]]!=2)return 0;
}
}
for(int i=0;i<(int)dua.size()-1;i++){
ans[dua[i]][dua[i+1]]=1;
ans[dua[i+1]][dua[i]]=1;
}
if(!dua.empty() && dua.size()>1){
ans[dua[0]][dua.back()]=1;
ans[dua.back()][dua[0]]=1;
}
if(!satu.empty() && !dua.empty()){
ans[dua.back()][satu[0]]=1;
ans[satu[0]][dua.back()]=1;
}
for(int i=0;i<(int)satu.size()-1;i++){
ans[satu[i]][satu[i+1]]=1;
ans[satu[i+1]][satu[i]]=1;
}
}
build(ans);
return 1;
}
Compilation message
supertrees.cpp: In function 'int construct(std::vector<std::vector<int> >)':
supertrees.cpp:43:16: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
43 | for(int j=0;j<kel[i].size();j++){
| ~^~~~~~~~~~~~~~
supertrees.cpp:45:17: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
45 | for(int k=0;k<kel[i].size();k++){
| ~^~~~~~~~~~~~~~
supertrees.cpp:58:16: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
58 | for(int j=0;j<satu.size();j++){
| ~^~~~~~~~~~~~
supertrees.cpp:59:17: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
59 | for(int k=0;k<kel[i].size();k++){
| ~^~~~~~~~~~~~~~
supertrees.cpp:74:16: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
74 | for(int i=0;i<dua.size();i++){
| ~^~~~~~~~~~~
supertrees.cpp:75:17: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
75 | for(int j=0;j<dua.size();j++){
| ~^~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
512 KB |
Output is correct |
2 |
Correct |
1 ms |
512 KB |
Output is correct |
3 |
Correct |
1 ms |
384 KB |
Output is correct |
4 |
Correct |
1 ms |
384 KB |
Output is correct |
5 |
Correct |
1 ms |
384 KB |
Output is correct |
6 |
Correct |
11 ms |
1408 KB |
Output is correct |
7 |
Correct |
255 ms |
22256 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
512 KB |
Output is correct |
2 |
Correct |
1 ms |
512 KB |
Output is correct |
3 |
Correct |
1 ms |
384 KB |
Output is correct |
4 |
Correct |
1 ms |
384 KB |
Output is correct |
5 |
Correct |
1 ms |
384 KB |
Output is correct |
6 |
Correct |
11 ms |
1408 KB |
Output is correct |
7 |
Correct |
255 ms |
22256 KB |
Output is correct |
8 |
Correct |
1 ms |
384 KB |
Output is correct |
9 |
Correct |
1 ms |
384 KB |
Output is correct |
10 |
Correct |
1 ms |
384 KB |
Output is correct |
11 |
Correct |
1 ms |
384 KB |
Output is correct |
12 |
Correct |
10 ms |
1368 KB |
Output is correct |
13 |
Correct |
248 ms |
24020 KB |
Output is correct |
14 |
Correct |
1 ms |
384 KB |
Output is correct |
15 |
Correct |
1 ms |
384 KB |
Output is correct |
16 |
Correct |
6 ms |
896 KB |
Output is correct |
17 |
Correct |
127 ms |
14184 KB |
Output is correct |
18 |
Correct |
1 ms |
384 KB |
Output is correct |
19 |
Correct |
1 ms |
384 KB |
Output is correct |
20 |
Correct |
65 ms |
6252 KB |
Output is correct |
21 |
Correct |
254 ms |
23652 KB |
Output is correct |
22 |
Correct |
250 ms |
24164 KB |
Output is correct |
23 |
Correct |
256 ms |
22116 KB |
Output is correct |
24 |
Correct |
259 ms |
24036 KB |
Output is correct |
25 |
Correct |
115 ms |
15844 KB |
Output is correct |
26 |
Correct |
118 ms |
16104 KB |
Output is correct |
27 |
Correct |
264 ms |
22192 KB |
Output is correct |
28 |
Correct |
258 ms |
24036 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
384 KB |
Output is correct |
2 |
Correct |
1 ms |
384 KB |
Output is correct |
3 |
Correct |
1 ms |
384 KB |
Output is correct |
4 |
Correct |
1 ms |
384 KB |
Output is correct |
5 |
Correct |
1 ms |
384 KB |
Output is correct |
6 |
Correct |
0 ms |
384 KB |
Output is correct |
7 |
Correct |
1 ms |
384 KB |
Output is correct |
8 |
Correct |
11 ms |
1368 KB |
Output is correct |
9 |
Correct |
251 ms |
24040 KB |
Output is correct |
10 |
Correct |
1 ms |
512 KB |
Output is correct |
11 |
Correct |
1 ms |
384 KB |
Output is correct |
12 |
Correct |
11 ms |
1280 KB |
Output is correct |
13 |
Correct |
256 ms |
22172 KB |
Output is correct |
14 |
Correct |
1 ms |
384 KB |
Output is correct |
15 |
Correct |
1 ms |
384 KB |
Output is correct |
16 |
Correct |
6 ms |
1024 KB |
Output is correct |
17 |
Correct |
129 ms |
14184 KB |
Output is correct |
18 |
Correct |
1 ms |
384 KB |
Output is correct |
19 |
Correct |
1 ms |
384 KB |
Output is correct |
20 |
Correct |
1 ms |
384 KB |
Output is correct |
21 |
Correct |
68 ms |
6260 KB |
Output is correct |
22 |
Correct |
258 ms |
23652 KB |
Output is correct |
23 |
Correct |
253 ms |
24036 KB |
Output is correct |
24 |
Correct |
261 ms |
22116 KB |
Output is correct |
25 |
Correct |
115 ms |
16100 KB |
Output is correct |
26 |
Correct |
117 ms |
15844 KB |
Output is correct |
27 |
Correct |
253 ms |
24036 KB |
Output is correct |
28 |
Correct |
263 ms |
22120 KB |
Output is correct |
29 |
Correct |
113 ms |
16100 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
384 KB |
Output is correct |
2 |
Correct |
1 ms |
384 KB |
Output is correct |
3 |
Correct |
1 ms |
384 KB |
Output is correct |
4 |
Correct |
65 ms |
6260 KB |
Output is correct |
5 |
Correct |
261 ms |
23652 KB |
Output is correct |
6 |
Correct |
252 ms |
24032 KB |
Output is correct |
7 |
Correct |
263 ms |
22116 KB |
Output is correct |
8 |
Correct |
1 ms |
384 KB |
Output is correct |
9 |
Correct |
64 ms |
6248 KB |
Output is correct |
10 |
Correct |
264 ms |
23652 KB |
Output is correct |
11 |
Correct |
255 ms |
24036 KB |
Output is correct |
12 |
Correct |
268 ms |
22120 KB |
Output is correct |
13 |
Correct |
1 ms |
384 KB |
Output is correct |
14 |
Correct |
1 ms |
384 KB |
Output is correct |
15 |
Correct |
1 ms |
384 KB |
Output is correct |
16 |
Incorrect |
36 ms |
4460 KB |
Answer gives possible 0 while actual possible 1 |
17 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
512 KB |
Output is correct |
2 |
Correct |
1 ms |
512 KB |
Output is correct |
3 |
Correct |
1 ms |
384 KB |
Output is correct |
4 |
Correct |
1 ms |
384 KB |
Output is correct |
5 |
Correct |
1 ms |
384 KB |
Output is correct |
6 |
Correct |
11 ms |
1408 KB |
Output is correct |
7 |
Correct |
255 ms |
22256 KB |
Output is correct |
8 |
Correct |
1 ms |
384 KB |
Output is correct |
9 |
Correct |
1 ms |
384 KB |
Output is correct |
10 |
Correct |
1 ms |
384 KB |
Output is correct |
11 |
Correct |
1 ms |
384 KB |
Output is correct |
12 |
Correct |
10 ms |
1368 KB |
Output is correct |
13 |
Correct |
248 ms |
24020 KB |
Output is correct |
14 |
Correct |
1 ms |
384 KB |
Output is correct |
15 |
Correct |
1 ms |
384 KB |
Output is correct |
16 |
Correct |
6 ms |
896 KB |
Output is correct |
17 |
Correct |
127 ms |
14184 KB |
Output is correct |
18 |
Correct |
1 ms |
384 KB |
Output is correct |
19 |
Correct |
1 ms |
384 KB |
Output is correct |
20 |
Correct |
65 ms |
6252 KB |
Output is correct |
21 |
Correct |
254 ms |
23652 KB |
Output is correct |
22 |
Correct |
250 ms |
24164 KB |
Output is correct |
23 |
Correct |
256 ms |
22116 KB |
Output is correct |
24 |
Correct |
259 ms |
24036 KB |
Output is correct |
25 |
Correct |
115 ms |
15844 KB |
Output is correct |
26 |
Correct |
118 ms |
16104 KB |
Output is correct |
27 |
Correct |
264 ms |
22192 KB |
Output is correct |
28 |
Correct |
258 ms |
24036 KB |
Output is correct |
29 |
Correct |
1 ms |
384 KB |
Output is correct |
30 |
Correct |
1 ms |
384 KB |
Output is correct |
31 |
Correct |
1 ms |
384 KB |
Output is correct |
32 |
Correct |
1 ms |
384 KB |
Output is correct |
33 |
Correct |
1 ms |
384 KB |
Output is correct |
34 |
Correct |
0 ms |
384 KB |
Output is correct |
35 |
Correct |
1 ms |
384 KB |
Output is correct |
36 |
Correct |
11 ms |
1368 KB |
Output is correct |
37 |
Correct |
251 ms |
24040 KB |
Output is correct |
38 |
Correct |
1 ms |
512 KB |
Output is correct |
39 |
Correct |
1 ms |
384 KB |
Output is correct |
40 |
Correct |
11 ms |
1280 KB |
Output is correct |
41 |
Correct |
256 ms |
22172 KB |
Output is correct |
42 |
Correct |
1 ms |
384 KB |
Output is correct |
43 |
Correct |
1 ms |
384 KB |
Output is correct |
44 |
Correct |
6 ms |
1024 KB |
Output is correct |
45 |
Correct |
129 ms |
14184 KB |
Output is correct |
46 |
Correct |
1 ms |
384 KB |
Output is correct |
47 |
Correct |
1 ms |
384 KB |
Output is correct |
48 |
Correct |
1 ms |
384 KB |
Output is correct |
49 |
Correct |
68 ms |
6260 KB |
Output is correct |
50 |
Correct |
258 ms |
23652 KB |
Output is correct |
51 |
Correct |
253 ms |
24036 KB |
Output is correct |
52 |
Correct |
261 ms |
22116 KB |
Output is correct |
53 |
Correct |
115 ms |
16100 KB |
Output is correct |
54 |
Correct |
117 ms |
15844 KB |
Output is correct |
55 |
Correct |
253 ms |
24036 KB |
Output is correct |
56 |
Correct |
263 ms |
22120 KB |
Output is correct |
57 |
Correct |
113 ms |
16100 KB |
Output is correct |
58 |
Correct |
1 ms |
384 KB |
Output is correct |
59 |
Correct |
1 ms |
384 KB |
Output is correct |
60 |
Correct |
6 ms |
896 KB |
Output is correct |
61 |
Correct |
127 ms |
13544 KB |
Output is correct |
62 |
Correct |
1 ms |
384 KB |
Output is correct |
63 |
Correct |
1 ms |
384 KB |
Output is correct |
64 |
Correct |
1 ms |
384 KB |
Output is correct |
65 |
Incorrect |
30 ms |
4340 KB |
Answer gives possible 0 while actual possible 1 |
66 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
512 KB |
Output is correct |
2 |
Correct |
1 ms |
512 KB |
Output is correct |
3 |
Correct |
1 ms |
384 KB |
Output is correct |
4 |
Correct |
1 ms |
384 KB |
Output is correct |
5 |
Correct |
1 ms |
384 KB |
Output is correct |
6 |
Correct |
11 ms |
1408 KB |
Output is correct |
7 |
Correct |
255 ms |
22256 KB |
Output is correct |
8 |
Correct |
1 ms |
384 KB |
Output is correct |
9 |
Correct |
1 ms |
384 KB |
Output is correct |
10 |
Correct |
1 ms |
384 KB |
Output is correct |
11 |
Correct |
1 ms |
384 KB |
Output is correct |
12 |
Correct |
10 ms |
1368 KB |
Output is correct |
13 |
Correct |
248 ms |
24020 KB |
Output is correct |
14 |
Correct |
1 ms |
384 KB |
Output is correct |
15 |
Correct |
1 ms |
384 KB |
Output is correct |
16 |
Correct |
6 ms |
896 KB |
Output is correct |
17 |
Correct |
127 ms |
14184 KB |
Output is correct |
18 |
Correct |
1 ms |
384 KB |
Output is correct |
19 |
Correct |
1 ms |
384 KB |
Output is correct |
20 |
Correct |
65 ms |
6252 KB |
Output is correct |
21 |
Correct |
254 ms |
23652 KB |
Output is correct |
22 |
Correct |
250 ms |
24164 KB |
Output is correct |
23 |
Correct |
256 ms |
22116 KB |
Output is correct |
24 |
Correct |
259 ms |
24036 KB |
Output is correct |
25 |
Correct |
115 ms |
15844 KB |
Output is correct |
26 |
Correct |
118 ms |
16104 KB |
Output is correct |
27 |
Correct |
264 ms |
22192 KB |
Output is correct |
28 |
Correct |
258 ms |
24036 KB |
Output is correct |
29 |
Correct |
1 ms |
384 KB |
Output is correct |
30 |
Correct |
1 ms |
384 KB |
Output is correct |
31 |
Correct |
1 ms |
384 KB |
Output is correct |
32 |
Correct |
1 ms |
384 KB |
Output is correct |
33 |
Correct |
1 ms |
384 KB |
Output is correct |
34 |
Correct |
0 ms |
384 KB |
Output is correct |
35 |
Correct |
1 ms |
384 KB |
Output is correct |
36 |
Correct |
11 ms |
1368 KB |
Output is correct |
37 |
Correct |
251 ms |
24040 KB |
Output is correct |
38 |
Correct |
1 ms |
512 KB |
Output is correct |
39 |
Correct |
1 ms |
384 KB |
Output is correct |
40 |
Correct |
11 ms |
1280 KB |
Output is correct |
41 |
Correct |
256 ms |
22172 KB |
Output is correct |
42 |
Correct |
1 ms |
384 KB |
Output is correct |
43 |
Correct |
1 ms |
384 KB |
Output is correct |
44 |
Correct |
6 ms |
1024 KB |
Output is correct |
45 |
Correct |
129 ms |
14184 KB |
Output is correct |
46 |
Correct |
1 ms |
384 KB |
Output is correct |
47 |
Correct |
1 ms |
384 KB |
Output is correct |
48 |
Correct |
1 ms |
384 KB |
Output is correct |
49 |
Correct |
68 ms |
6260 KB |
Output is correct |
50 |
Correct |
258 ms |
23652 KB |
Output is correct |
51 |
Correct |
253 ms |
24036 KB |
Output is correct |
52 |
Correct |
261 ms |
22116 KB |
Output is correct |
53 |
Correct |
115 ms |
16100 KB |
Output is correct |
54 |
Correct |
117 ms |
15844 KB |
Output is correct |
55 |
Correct |
253 ms |
24036 KB |
Output is correct |
56 |
Correct |
263 ms |
22120 KB |
Output is correct |
57 |
Correct |
113 ms |
16100 KB |
Output is correct |
58 |
Correct |
1 ms |
384 KB |
Output is correct |
59 |
Correct |
1 ms |
384 KB |
Output is correct |
60 |
Correct |
1 ms |
384 KB |
Output is correct |
61 |
Correct |
65 ms |
6260 KB |
Output is correct |
62 |
Correct |
261 ms |
23652 KB |
Output is correct |
63 |
Correct |
252 ms |
24032 KB |
Output is correct |
64 |
Correct |
263 ms |
22116 KB |
Output is correct |
65 |
Correct |
1 ms |
384 KB |
Output is correct |
66 |
Correct |
64 ms |
6248 KB |
Output is correct |
67 |
Correct |
264 ms |
23652 KB |
Output is correct |
68 |
Correct |
255 ms |
24036 KB |
Output is correct |
69 |
Correct |
268 ms |
22120 KB |
Output is correct |
70 |
Correct |
1 ms |
384 KB |
Output is correct |
71 |
Correct |
1 ms |
384 KB |
Output is correct |
72 |
Correct |
1 ms |
384 KB |
Output is correct |
73 |
Incorrect |
36 ms |
4460 KB |
Answer gives possible 0 while actual possible 1 |
74 |
Halted |
0 ms |
0 KB |
- |