#include "supertrees.h"
using namespace std;
#define AE(a,b) ans[a][b]=ans[b][a]=1
struct dsu {
int par[1010];
int abp(int n){
return par[n]?par[n]=abp(par[n]):n;
}
void merge(int a,int b){
a=abp(a+1);
b=abp(b+1);
if(a-b)par[a]=b;
}
int CC(int n){
return abp(n+1)-1;
}
} comps, chains, CCs;
int construct(vector<vector<int>> p) {
for(auto i:p)
for(auto j:i)
if(j==3)
return 0;
int n=p.size();
vector<vector<int>>ans(n,vector<int>(n));
for(int i=0;i<n;i++)
for(int j=0;j<n;j++)
if(p[i][j])
CCs.merge(i,j);
for(int i=0;i<n;i++)
for(int j=0;j<n;j++)
if(p[i][j]==1)
chains.merge(i,j);
for(int i=0;i<n;i++)
for(int j=0;j<n;j++) if(p[i][j]==2)
comps.merge(chains.CC(i),chains.CC(j));
for(int i=0;i<n;i++)
for(int j=0;j<n;j++)
if(!p[i][j]) {
if(CCs.CC(i)==CCs.CC(j))
return 0;
} else if(p[i][j]==2)
if(chains.CC(i)==chains.CC(j))
return 0;
vector<int>thgs[1010];
for(int i=0;i<n;i++)
if(chains.CC(i)-i)
AE(chains.CC(i),i);
else thgs[comps.CC(i)].push_back(i);
for(int i=0;i<n;i++){
if(thgs[i].size()<2)continue;
thgs[i].push_back(thgs[i][0]);
for(int j=1;j<thgs[i].size();j++)
AE(thgs[i][j],thgs[i][j-1]);
}
build(ans);
return 1;
}
Compilation message
supertrees.cpp: In function 'int construct(std::vector<std::vector<int> >)':
supertrees.cpp:52:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
52 | for(int j=1;j<thgs[i].size();j++)
| ~^~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 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 |
348 KB |
Output is correct |
6 |
Correct |
5 ms |
1352 KB |
Output is correct |
7 |
Correct |
98 ms |
24144 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 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 |
348 KB |
Output is correct |
6 |
Correct |
5 ms |
1352 KB |
Output is correct |
7 |
Correct |
98 ms |
24144 KB |
Output is correct |
8 |
Correct |
0 ms |
348 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 |
432 KB |
Output is correct |
12 |
Correct |
4 ms |
1368 KB |
Output is correct |
13 |
Correct |
98 ms |
23932 KB |
Output is correct |
14 |
Correct |
0 ms |
344 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
3 ms |
856 KB |
Output is correct |
17 |
Correct |
69 ms |
14084 KB |
Output is correct |
18 |
Correct |
0 ms |
344 KB |
Output is correct |
19 |
Correct |
0 ms |
348 KB |
Output is correct |
20 |
Correct |
24 ms |
6288 KB |
Output is correct |
21 |
Correct |
101 ms |
24148 KB |
Output is correct |
22 |
Correct |
96 ms |
24168 KB |
Output is correct |
23 |
Correct |
105 ms |
23976 KB |
Output is correct |
24 |
Correct |
103 ms |
24148 KB |
Output is correct |
25 |
Correct |
46 ms |
14164 KB |
Output is correct |
26 |
Correct |
45 ms |
14204 KB |
Output is correct |
27 |
Correct |
121 ms |
24148 KB |
Output is correct |
28 |
Correct |
95 ms |
24144 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 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 |
Incorrect |
0 ms |
348 KB |
Answer gives possible 1 while actual possible 0 |
5 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
600 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
24 ms |
6260 KB |
Output is correct |
5 |
Correct |
101 ms |
24108 KB |
Output is correct |
6 |
Correct |
96 ms |
24144 KB |
Output is correct |
7 |
Correct |
113 ms |
24060 KB |
Output is correct |
8 |
Correct |
1 ms |
348 KB |
Output is correct |
9 |
Correct |
24 ms |
6420 KB |
Output is correct |
10 |
Correct |
100 ms |
24060 KB |
Output is correct |
11 |
Correct |
96 ms |
24148 KB |
Output is correct |
12 |
Correct |
108 ms |
24148 KB |
Output is correct |
13 |
Correct |
1 ms |
348 KB |
Output is correct |
14 |
Correct |
0 ms |
348 KB |
Output is correct |
15 |
Correct |
1 ms |
348 KB |
Output is correct |
16 |
Correct |
27 ms |
6224 KB |
Output is correct |
17 |
Correct |
98 ms |
23968 KB |
Output is correct |
18 |
Correct |
100 ms |
24056 KB |
Output is correct |
19 |
Correct |
97 ms |
24060 KB |
Output is correct |
20 |
Correct |
98 ms |
24148 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 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 |
348 KB |
Output is correct |
6 |
Correct |
5 ms |
1352 KB |
Output is correct |
7 |
Correct |
98 ms |
24144 KB |
Output is correct |
8 |
Correct |
0 ms |
348 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 |
432 KB |
Output is correct |
12 |
Correct |
4 ms |
1368 KB |
Output is correct |
13 |
Correct |
98 ms |
23932 KB |
Output is correct |
14 |
Correct |
0 ms |
344 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
3 ms |
856 KB |
Output is correct |
17 |
Correct |
69 ms |
14084 KB |
Output is correct |
18 |
Correct |
0 ms |
344 KB |
Output is correct |
19 |
Correct |
0 ms |
348 KB |
Output is correct |
20 |
Correct |
24 ms |
6288 KB |
Output is correct |
21 |
Correct |
101 ms |
24148 KB |
Output is correct |
22 |
Correct |
96 ms |
24168 KB |
Output is correct |
23 |
Correct |
105 ms |
23976 KB |
Output is correct |
24 |
Correct |
103 ms |
24148 KB |
Output is correct |
25 |
Correct |
46 ms |
14164 KB |
Output is correct |
26 |
Correct |
45 ms |
14204 KB |
Output is correct |
27 |
Correct |
121 ms |
24148 KB |
Output is correct |
28 |
Correct |
95 ms |
24144 KB |
Output is correct |
29 |
Correct |
0 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 |
Incorrect |
0 ms |
348 KB |
Answer gives possible 1 while actual possible 0 |
33 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 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 |
348 KB |
Output is correct |
6 |
Correct |
5 ms |
1352 KB |
Output is correct |
7 |
Correct |
98 ms |
24144 KB |
Output is correct |
8 |
Correct |
0 ms |
348 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 |
432 KB |
Output is correct |
12 |
Correct |
4 ms |
1368 KB |
Output is correct |
13 |
Correct |
98 ms |
23932 KB |
Output is correct |
14 |
Correct |
0 ms |
344 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
3 ms |
856 KB |
Output is correct |
17 |
Correct |
69 ms |
14084 KB |
Output is correct |
18 |
Correct |
0 ms |
344 KB |
Output is correct |
19 |
Correct |
0 ms |
348 KB |
Output is correct |
20 |
Correct |
24 ms |
6288 KB |
Output is correct |
21 |
Correct |
101 ms |
24148 KB |
Output is correct |
22 |
Correct |
96 ms |
24168 KB |
Output is correct |
23 |
Correct |
105 ms |
23976 KB |
Output is correct |
24 |
Correct |
103 ms |
24148 KB |
Output is correct |
25 |
Correct |
46 ms |
14164 KB |
Output is correct |
26 |
Correct |
45 ms |
14204 KB |
Output is correct |
27 |
Correct |
121 ms |
24148 KB |
Output is correct |
28 |
Correct |
95 ms |
24144 KB |
Output is correct |
29 |
Correct |
0 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 |
Incorrect |
0 ms |
348 KB |
Answer gives possible 1 while actual possible 0 |
33 |
Halted |
0 ms |
0 KB |
- |