This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
#include "supertrees.h"
#define loop(i, a, b) for(long long i=a;i<b;i++)
#define pool(i, a, b) for(long long i=a-1;i>=b;i--)
#define fore(i, a) for(auto&& i:a)
#define fi first
#define se second
#define ps(a) push_back(a)
#define pb(a) pop_back(a)
#define sc scanf
#define vc vector
#define pa pair<ll, ll>
#define ll int
#define lb lower_bound
#define ub upper_bound
#define all(a) a.begin(), a.end()
#define llmax LLONG_MAX/2
#define llmin -LLONG_MAX/2
using namespace std;
#define mn 1010
#define pa pair<ll, ll>
#define ld long double
ll arr[mn], sti[mn], com[mn];
vc<ll> ss[mn], cc[mn];
int construct(vc<vc<int>> p){
ll n=p.size();
loop(i, 0, n) arr[i]=-1, sti[i]=-1, com[i]=-1;
ll cnt=0;
loop(i, 0, n){
loop(j, 0, i){
if(p[i][j]==3) return 0;
if(p[i][j]){
if(arr[i]==-1) arr[i]=arr[j];
else if(arr[i]!=arr[j]) return 0;
}
else{
if(arr[i]==arr[j])return 0;
}
}
if(arr[i]==-1) arr[i]=cnt++;
}
loop(i, 0, n){
loop(j, 0, i){
if(p[i][j]){if(arr[i]!=arr[j])return 0;}
else {if(arr[i]==arr[j])return 0;}
}
}
ll cur=0;
loop(i, 0, n){
loop(j, 0, i){
if(p[i][j]==1){
if(sti[i]==-1) sti[i]=sti[j];
else if(sti[i]!=sti[j]) return 0;
}
else{
if(sti[i]==sti[j])return 0;
}
}
if(sti[i]==-1) sti[i]=cur++;
}
loop(i, 0, n){
loop(j, 0, i){
if(p[i][j]==1){ if(sti[i]!=sti[j])return 0;}
else{ if(sti[i]==sti[j])return 0;}
}
}
loop(i, 0, n) ss[sti[i]].ps(i);
loop(i, 0, n) com[sti[i]]=arr[i];
loop(i, 0, cur) cc[com[i]].ps(i);
vc<int> samp(n, 0);
vc<vc<int>> ans(n, samp);
loop(i, 0, cnt){
if(cc[i].size()==0) return 1;
if(cc[i].size()==1){
vc<ll> u=ss[cc[i][0]];
if(u.size()>1) loop(v, 0, (ll)u.size()-1) ans[u[v]][u[v+1]]=1, ans[u[v+1]][u[v]]=1;
}
else if(cc[i].size()==2) return 0;
else{
fore(t, cc[i]){
vc<ll> u=ss[t];
if(u.size()>1) loop(v, 0, (ll)u.size()-1) ans[u[v]][u[v+1]]=1, ans[u[v+1]][u[v]]=1;
}
loop(t, 0, cc[i].size()){
ans[ss[cc[i][t]][0]][ss[cc[i][((ll)t+1)%((ll)cc[i].size())]][0]]=1;
ans[ss[cc[i][(t+1)%((ll)cc[i].size())]][0]][ss[cc[i][t]][0]]=1;
}
}
}
build(ans);
return 1;
}
Compilation message (stderr)
supertrees.cpp: In function 'int construct(std::vector<std::vector<int> >)':
supertrees.cpp:3:42: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
3 | #define loop(i, a, b) for(long long i=a;i<b;i++)
......
85 | loop(t, 0, cc[i].size()){
| ~~~~~~~~~~~~~~~~~~
supertrees.cpp:85:13: note: in expansion of macro 'loop'
85 | loop(t, 0, cc[i].size()){
| ^~~~
# | 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... |