#include <bits/stdc++.h>
//#define test
#ifndef test
#include "supertrees.h"
#endif // testing
using namespace std;
#ifdef test
vector<vector<int>> in;
void build(vector<vector<int>> v)
{
int n = v.size();
for(int i=0;i<n;i++)
{
for(int j=0;j<n;j++)
{
cout<<v[i][j]<<' ';
}
cout<<'\n';
}
}
#endif // testing
vector<vector<int>> rez;
int t[1005],rang[1005];
int reprezentant(int x)
{
if(x==t[x])
{
return x;
}
t[x] = reprezentant(t[x]);
return t[x];
}
void uneste(int x, int y)
{
x = reprezentant(x);
y = reprezentant(y);
if(x==y)
{
return;
}
if(rang[x]<rang[y])
{
t[x] = y;
rang[y] += rang[x];
}
else
{
t[y] = x;
rang[x] += y;
}
}
int construct(vector<vector<int>> p)
{
int n = p.size();
for(int i=0;i<n;i++)
{
t[i] = i;
rang[i] = 1;
}
for(int i=0;i<n;i++)
{
for(int j=0;j<n;j++)
{
if(p[i][j] && i!=j)
{
if(p[i][j]==3)
{
return 0;
}
uneste(i,j);
}
}
}
rez.resize(n);
for(int i=0;i<n;i++)
{
rez[i].resize(n);
}
for(int i=0;i<n;i++)
{
vector<int> v;
for(int j=0;j<n;j++)
{
if(reprezentant(j)==i)
{
v.push_back(j);
}
}
for(int j=0;j<v.size();j++)
{
for(int k=j+1;k<v.size();k++)
{
if(!p[v[j]][v[k]])
{
return 0;
}
}
}
for(int j=1;j<v.size();j++)
{
rez[v[j-1]][v[j]] = rez[v[j]][v[j-1]] = 1;
}
}
build(rez);
return 1;
}
#ifdef test
int main()
{
freopen("nr.in","r",stdin);
freopen("nr.out","w",stdout);
int n;
cin>>n;
in.resize(n);
for(int i=0;i<n;i++)
{
in[i].resize(n);
}
for(int i=0;i<n;i++)
{
for(int j=0;j<n;j++)
{
cin>>in[i][j];
}
}
construct(in);
return 0;
}
#endif // test
Compilation message
supertrees.cpp: In function 'int construct(std::vector<std::vector<int> >)':
supertrees.cpp:102:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
102 | for(int j=0;j<v.size();j++)
| ~^~~~~~~~~
supertrees.cpp:104:28: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
104 | for(int k=j+1;k<v.size();k++)
| ~^~~~~~~~~
supertrees.cpp:112:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
112 | for(int j=1;j<v.size();j++)
| ~^~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
8 ms |
1108 KB |
Output is correct |
7 |
Correct |
177 ms |
21956 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
8 ms |
1108 KB |
Output is correct |
7 |
Correct |
177 ms |
21956 KB |
Output is correct |
8 |
Correct |
0 ms |
212 KB |
Output is correct |
9 |
Correct |
0 ms |
212 KB |
Output is correct |
10 |
Correct |
0 ms |
212 KB |
Output is correct |
11 |
Correct |
0 ms |
212 KB |
Output is correct |
12 |
Correct |
12 ms |
1172 KB |
Output is correct |
13 |
Correct |
178 ms |
21996 KB |
Output is correct |
14 |
Correct |
0 ms |
212 KB |
Output is correct |
15 |
Correct |
0 ms |
212 KB |
Output is correct |
16 |
Correct |
3 ms |
724 KB |
Output is correct |
17 |
Correct |
85 ms |
12024 KB |
Output is correct |
18 |
Correct |
0 ms |
212 KB |
Output is correct |
19 |
Correct |
0 ms |
212 KB |
Output is correct |
20 |
Correct |
46 ms |
5664 KB |
Output is correct |
21 |
Correct |
178 ms |
23932 KB |
Output is correct |
22 |
Correct |
178 ms |
24012 KB |
Output is correct |
23 |
Correct |
203 ms |
24000 KB |
Output is correct |
24 |
Correct |
204 ms |
24012 KB |
Output is correct |
25 |
Correct |
69 ms |
14080 KB |
Output is correct |
26 |
Correct |
68 ms |
14068 KB |
Output is correct |
27 |
Correct |
182 ms |
24008 KB |
Output is correct |
28 |
Correct |
175 ms |
23944 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Incorrect |
0 ms |
212 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 |
212 KB |
Output is correct |
2 |
Incorrect |
0 ms |
212 KB |
Too few ways to get from 0 to 1, should be 2 found 1 |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
8 ms |
1108 KB |
Output is correct |
7 |
Correct |
177 ms |
21956 KB |
Output is correct |
8 |
Correct |
0 ms |
212 KB |
Output is correct |
9 |
Correct |
0 ms |
212 KB |
Output is correct |
10 |
Correct |
0 ms |
212 KB |
Output is correct |
11 |
Correct |
0 ms |
212 KB |
Output is correct |
12 |
Correct |
12 ms |
1172 KB |
Output is correct |
13 |
Correct |
178 ms |
21996 KB |
Output is correct |
14 |
Correct |
0 ms |
212 KB |
Output is correct |
15 |
Correct |
0 ms |
212 KB |
Output is correct |
16 |
Correct |
3 ms |
724 KB |
Output is correct |
17 |
Correct |
85 ms |
12024 KB |
Output is correct |
18 |
Correct |
0 ms |
212 KB |
Output is correct |
19 |
Correct |
0 ms |
212 KB |
Output is correct |
20 |
Correct |
46 ms |
5664 KB |
Output is correct |
21 |
Correct |
178 ms |
23932 KB |
Output is correct |
22 |
Correct |
178 ms |
24012 KB |
Output is correct |
23 |
Correct |
203 ms |
24000 KB |
Output is correct |
24 |
Correct |
204 ms |
24012 KB |
Output is correct |
25 |
Correct |
69 ms |
14080 KB |
Output is correct |
26 |
Correct |
68 ms |
14068 KB |
Output is correct |
27 |
Correct |
182 ms |
24008 KB |
Output is correct |
28 |
Correct |
175 ms |
23944 KB |
Output is correct |
29 |
Correct |
0 ms |
212 KB |
Output is correct |
30 |
Correct |
0 ms |
212 KB |
Output is correct |
31 |
Correct |
1 ms |
212 KB |
Output is correct |
32 |
Incorrect |
0 ms |
212 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 |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
8 ms |
1108 KB |
Output is correct |
7 |
Correct |
177 ms |
21956 KB |
Output is correct |
8 |
Correct |
0 ms |
212 KB |
Output is correct |
9 |
Correct |
0 ms |
212 KB |
Output is correct |
10 |
Correct |
0 ms |
212 KB |
Output is correct |
11 |
Correct |
0 ms |
212 KB |
Output is correct |
12 |
Correct |
12 ms |
1172 KB |
Output is correct |
13 |
Correct |
178 ms |
21996 KB |
Output is correct |
14 |
Correct |
0 ms |
212 KB |
Output is correct |
15 |
Correct |
0 ms |
212 KB |
Output is correct |
16 |
Correct |
3 ms |
724 KB |
Output is correct |
17 |
Correct |
85 ms |
12024 KB |
Output is correct |
18 |
Correct |
0 ms |
212 KB |
Output is correct |
19 |
Correct |
0 ms |
212 KB |
Output is correct |
20 |
Correct |
46 ms |
5664 KB |
Output is correct |
21 |
Correct |
178 ms |
23932 KB |
Output is correct |
22 |
Correct |
178 ms |
24012 KB |
Output is correct |
23 |
Correct |
203 ms |
24000 KB |
Output is correct |
24 |
Correct |
204 ms |
24012 KB |
Output is correct |
25 |
Correct |
69 ms |
14080 KB |
Output is correct |
26 |
Correct |
68 ms |
14068 KB |
Output is correct |
27 |
Correct |
182 ms |
24008 KB |
Output is correct |
28 |
Correct |
175 ms |
23944 KB |
Output is correct |
29 |
Correct |
0 ms |
212 KB |
Output is correct |
30 |
Correct |
0 ms |
212 KB |
Output is correct |
31 |
Correct |
1 ms |
212 KB |
Output is correct |
32 |
Incorrect |
0 ms |
212 KB |
Answer gives possible 1 while actual possible 0 |
33 |
Halted |
0 ms |
0 KB |
- |