#include <bits/stdc++.h>
#include "supertrees.h"
#define inf 1000000007
#define mod 1000000007
#define rnd() rand_num()
#define bigrnd() dis(rand_num)
//#pragma GCC optimize("Ofast","inline","-ffast-math")
//#pragma GCC target("avx,sse2,sse3,sse4,mmx")
//#define int long long
using namespace std;
unsigned sed=std::chrono::system_clock::now().time_since_epoch().count();
mt19937 rand_num(sed);
uniform_int_distribution<long long> dis(0,inf);
template <typename T> void read(T &x){
x=0;char ch=getchar();int fh=1;
while (ch<'0'||ch>'9'){if (ch=='-')fh=-1;ch=getchar();}
while (ch>='0'&&ch<='9')x=x*10+ch-'0',ch=getchar();
x*=fh;
}
template <typename T> void write(T x) {
if (x<0) x=-x,putchar('-');
if (x>9) write(x/10);
putchar(x%10+'0');
}
template <typename T> void writeln(T x) {
write(x);
puts("");
}
int n;
int fa[1005];
int fa1[1005];
int g[1005][1005];
int fnd(int x)
{
if(fa[x]!=x) fa[x]=fnd(fa[x]);
return fa[x];
}
int fnd1(int x)
{
if(fa1[x]!=x) fa1[x]=fnd1(fa1[x]);
return fa1[x];
}
int construct(vector<vector<int>> p)
{
n=p.size();
for(int i=0;i<n;++i)
fa[i]=i;
for(int i=0;i<n;++i)
for(int j=0;j<n;++j)
if(p[i][j]==3)
return 0;
else if(p[i][j])
fa[fnd(i)]=fnd(j);
for(int i=0;i<n;++i)
for(int j=0;j<n;++j)
if(!p[i][j]&&fnd(i)==fnd(j))
return 0;
for(int i=0;i<n;++i)
fa1[i]=i;
for(int i=0;i<n;++i)
for(int j=0;j<n;++j)
if(p[i][j]==2&&fnd1(i)==fnd1(j))
return 0;
for(int i=0;i<n;++i)
if(fnd(i)==i)
{
vector<int> vec;
for(int j=0;j<n;++j)
if(fnd(j)==i)
vec.push_back(fnd1(j));
sort(vec.begin(),vec.end());
vec.erase(unique(vec.begin(),vec.end()),vec.end());
bool flag=false;
for(int j=0;j<vec.size();++j)
for(int k=j+1;k<vec.size();++k)
if(p[vec[j]][vec[k]]==2)
flag=true;
if(flag&&vec.size()<3) return 0;
if(flag)
{
for(int j=0;j+1<vec.size();++j)
g[vec[j]][vec[j+1]]=g[vec[j+1]][vec[j]]=1;
g[vec[0]][vec[vec.size()-1]]=g[vec[vec.size()-1]][vec[0]]=1;
}
for(int j=0;j<n;++j)
if(fnd1(j)!=j)
g[fnd1(j)][j]=g[j][fnd1(j)]=1;
}
vector<vector<int>> ans;
for(int i=0;i<n;++i)
{
vector<int> tmp;
for(int j=0;j<n;++j)
tmp.push_back(g[i][j]);
ans.push_back(tmp);
}
build(ans);
return 1;
}
Compilation message
supertrees.cpp: In function 'int construct(std::vector<std::vector<int> >)':
supertrees.cpp:74:17: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
74 | for(int j=0;j<vec.size();++j)
| ~^~~~~~~~~~~
supertrees.cpp:75:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
75 | for(int k=j+1;k<vec.size();++k)
| ~^~~~~~~~~~~
supertrees.cpp:81:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
81 | for(int j=0;j+1<vec.size();++j)
| ~~~^~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Incorrect |
1 ms |
204 KB |
Too few ways to get from 0 to 1, should be 1 found 0 |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Incorrect |
1 ms |
204 KB |
Too few ways to get from 0 to 1, should be 1 found 0 |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Correct |
1 ms |
204 KB |
Output is correct |
4 |
Correct |
0 ms |
204 KB |
Output is correct |
5 |
Correct |
1 ms |
204 KB |
Output is correct |
6 |
Correct |
1 ms |
204 KB |
Output is correct |
7 |
Correct |
1 ms |
204 KB |
Output is correct |
8 |
Correct |
10 ms |
1100 KB |
Output is correct |
9 |
Correct |
243 ms |
22024 KB |
Output is correct |
10 |
Correct |
1 ms |
332 KB |
Output is correct |
11 |
Correct |
1 ms |
332 KB |
Output is correct |
12 |
Correct |
11 ms |
1996 KB |
Output is correct |
13 |
Correct |
247 ms |
26072 KB |
Output is correct |
14 |
Correct |
1 ms |
204 KB |
Output is correct |
15 |
Correct |
1 ms |
204 KB |
Output is correct |
16 |
Correct |
5 ms |
588 KB |
Output is correct |
17 |
Correct |
146 ms |
8132 KB |
Output is correct |
18 |
Correct |
1 ms |
204 KB |
Output is correct |
19 |
Correct |
1 ms |
204 KB |
Output is correct |
20 |
Correct |
1 ms |
204 KB |
Output is correct |
21 |
Correct |
58 ms |
7564 KB |
Output is correct |
22 |
Correct |
234 ms |
27916 KB |
Output is correct |
23 |
Correct |
286 ms |
27908 KB |
Output is correct |
24 |
Correct |
245 ms |
27936 KB |
Output is correct |
25 |
Correct |
102 ms |
10240 KB |
Output is correct |
26 |
Correct |
94 ms |
10144 KB |
Output is correct |
27 |
Correct |
235 ms |
27916 KB |
Output is correct |
28 |
Correct |
277 ms |
27844 KB |
Output is correct |
29 |
Correct |
134 ms |
10240 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Incorrect |
0 ms |
204 KB |
Too few ways to get from 1 to 2, should be 1 found 0 |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Incorrect |
1 ms |
204 KB |
Too few ways to get from 0 to 1, should be 1 found 0 |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Incorrect |
1 ms |
204 KB |
Too few ways to get from 0 to 1, should be 1 found 0 |
3 |
Halted |
0 ms |
0 KB |
- |