This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#pragma GCC optimize ("Ofast")
#pragma GCC optimize ("O3")
#pragma GCC optimize ("unroll-loops")
//#pragma GCC target("avx,avx2,sse,sse2,ssse3,tune=native")
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define ll long long
#define ld long double
#define endl '\n'
#define all(a) a.begin(),a.end()
#define ull unsigned long long
#define y1 asjdlfaskavslbcjasndscf
#define ios ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define iter set< int >::iterator
#define iter1 multiset<int>::iterator
using namespace std;
using namespace __gnu_pbds;
template<class T>
using ordered_set=tree<T,null_type,less<T>,rb_tree_tag,tree_order_statistics_node_update>;
template<class T>
using ordered_multiset=tree<T,null_type,less_equal<T>,rb_tree_tag,tree_order_statistics_node_update>;
mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());
mt19937_64 rnd1(chrono::steady_clock::now().time_since_epoch().count());
//find_by_order
//order_of_key
//const int MAX_MEM=4e8;
//int mpos=0;
//char mem[MAX_MEM];
//
//inline void * operator new(size_t n){
// char *res=mem+mpos;
// mpos+=n;
// if (mpos>=MAX_MEM){
// cout<<"BAD"<<endl;
// exit(0);
// }
// return (void*)res;
//}
//
//inline void operator delete(void *) {}
const int N=1000+5;
const int inf=1e9+1e9;
const int mod=1e9+7;
const ld eps=1e-9;
#define COL 1
#if COL
#include "supertrees.h"
#include <vector>
#endif
void add(int x,int y,vector<vector<int>>&ans)
{
if (x==y)return;
ans[x][y]=1;
ans[y][x]=1;
}
int construct(vector<vector<int>> p) {
int n = p.size();
vector<vector<int>> ans;
for (int i = 0; i < n; i++) {
vector<int> row;
row.resize(n);
ans.push_back(row);
}
bitset<N>used1[n],used2[n];
bool used[n],used3[n];
int nxt[n];
fill(used,used+n,0);
fill(used3,used3+n,0);
fill(nxt,nxt+n,-1);
for (int i=0;i<n;++i){
for (int j=0;j<n;++j){
if (p[i][j]==1){
used1[i][j]=1;
}
if (p[i][j]==2){
used2[i][j]=1;
}
if (p[i][j]==3){
return 0;
}
}
}
for (int i=0;i<n;++i){
if (used3[i])continue;
vector<int>ver;
for (int j=0;j<n;++j){
if (used1[i][j]){
ver.pb(j);
}
}
if (!used[i]){
for (int j=0;j<ver.size();++j){
int to=ver[j];
used3[to]=1;
if (used1[to]!=used1[i]){
return 0;
}
if (used2[to]!=used2[i]){
return 0;
}
add(i,to,ans);
}
used[i]=1;
}
}
for (int i=0;i<n;++i){
if (used[i]){
nxt[i]=i;
for (int j=i+1;j<n;++j){
if (used[j]){
if ((used1[j]|used2[j])==(used1[i]|used2[i])){
nxt[i]=j;
break;
}
}
}
if (nxt[i]==i){
for (int j=0;j<i;++j){
if (used[j]){
if ((used1[j]|used2[j])==(used1[i]|used2[i])){
nxt[i]=j;
break;
}
}
}
}
}
}
for (int i=0;i<n;++i){
used3[i]=0;
}
for (int i=0;i<n;++i){
if (used[i]){
add(i,nxt[i],ans);
}
if (used3[i])continue;
if (used[i]){
int kol=1;
used3[i]=1;
bitset<N>c=used1[i];
int v=nxt[i];
while (v!=i){
used3[v]=1;
c|=used1[v];
v=nxt[v];
++kol;
}
c|=used1[i];
if (kol==2){
return 0;
}
bitset<N>r=(used1[i]|used2[i]);
if (c!=(used1[i]|used2[i])){
return 0;
}
}
}
#if !COL
for (int i=0;i<ans.size();++i){
for (int j=0;j<ans.size();++j){
cout<<ans[i][j]<<' ';
}
cout<<endl;
}
#endif
#if COL
build(ans);
#endif
return 1;
}
#if !COL
main ()
{
ios;
construct({
{1,1,2,2},
{1,1,2,2},
{2,2,1,2},
{2,2,2,1},
});
}
#endif
//4
//1 2 1 0
//1 3 1 0
//3 4 1 1
Compilation message (stderr)
supertrees.cpp: In function 'int construct(std::vector<std::vector<int> >)':
supertrees.cpp:109:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
109 | for (int j=0;j<ver.size();++j){
| ~^~~~~~~~~~~
supertrees.cpp:169:22: warning: variable 'r' set but not used [-Wunused-but-set-variable]
169 | bitset<N>r=(used1[i]|used2[i]);
| ^
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |