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 "supertrees.h"
//Bismillahirrahmanirrahim
#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx")
#include <bits/stdc++.h>
using namespace std;
typedef long long lo;
typedef pair< lo,lo > PII;
#define fi first
#define se second
#define mp make_pair
#define endl "\n"
#define pb push_back
#define fio() ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define FOR for(int i=0;i<n;i++)
#define mid ((start+end)/2)
#define ort ((bas+son)/2)
const lo inf = 1000000000000000000;
const lo KOK = 100000;
const lo LOG = 30;
const lo li = 1005;
const lo mod = 1000000007;
int m,k,flag,t,vis[li],no[li],fa[li],ofof[li];
int cev,ok[li];
string s;
vector<int> v[li],vec[li];
inline int dsu(int x){
if(x==fa[x])return x;
return fa[x]=dsu(fa[x]);
}
int construct(std::vector<std::vector<int>> p) {
int n = p.size();
FOR fa[i]=i;
std::vector<std::vector<int>> a;
for (int i = 0; i < n; i++) {
for(int j=0;j<n;j++){
//~ if(i==j)continue;
if(p[i][j]!=0){v[i].pb(j);}
if(i!=j && p[i][j]==1)flag=1;
}
}
FOR sort(v[i].begin(),v[i].end());
int say=0;
FOR{
if(ofof[i])continue;
ofof[i]=1;
for(int jj=0;jj<(int)v[i].size();jj++){
ofof[v[i][jj]]=1;
for(int j=0;j<jj;j++){
if(p[v[i][jj]][v[i][j]]==1)no[v[i][jj]]=1;
}
}
}
FOR{
if(vis[i])continue;
vis[i]=++say;
for(int jj=0;jj<(int)v[i].size();jj++){
int go=v[i][jj];
vis[go]=say;
if(no[go]==0)vec[say].pb(go);
if(v[go].size()!=v[i].size())return 0;
//~ cout<<i<<": : "<<go<<endl;
for(int ii=0;ii<(int)v[i].size();ii++){
//~ cout<<go<<" "<<i<<" ** "<<v[go][ii]<<" : : "<<v[i][ii]<<endl;
if(v[go][ii]!=v[i][ii])return 0;
}
}
}
for(int i=1;i<=say;i++)sort(vec[i].begin(),vec[i].end());
for(int i=1;i<=say;i++){
flag=0;
for(int j=(int)vec[i].size()-1;j>=0;j--){
for(int jj=0;jj<j;jj++){
if(p[vec[i][j]][vec[i][jj]]==2 && no[jj]==0 && no[j]==0){ok[vec[i][j]]=1;ok[vec[i][jj]]=1;flag=1;break;}
}
if(flag)break;
}
}
//~ if(flag==0){
FOR{
//~ cout<<i<<" ()() "<<ok[i]<<endl;
vector<int> vv;
int ind=0;
while(ind<(int)vec[vis[i]].size() && vec[vis[i]][ind]!=i)ind++;
//~ cout<<i<<" ** "<<vec[vis[i]][ind-1]<<"**"<<endl;
if(vec[vis[i]].size()==2){return 0;}
if(vec[vis[i]].size()==1){
for(int j=0;j<n;j++){
if(i==j){vv.pb(0);}
else if(j<i)vv.pb(a[j][i]);
else if(p[j][i]==1 && no[i]==0){vv.pb(1);fa[dsu(j)]=dsu(i);}
else if(j==dsu(i) && no[i]){vv.pb(1);}
else vv.pb(0);
}
a.pb(vv);
continue;
}
for(int j=0;j<n;j++){
if(i==j){vv.pb(0);}
else if(j<i)vv.pb(a[j][i]);
else if(p[j][i]==0){vv.pb(0);}
else if(p[j][i]==1 && no[i]==0){vv.pb(1);fa[j]=i;}
else if(j==fa[i] && no[i]){vv.pb(1);}
else if(((ind>0 && j==vec[vis[i]][ind-1]) || (ind+1<(int)vec[vis[i]].size() && j==vec[vis[i]][ind+1])))vv.pb(1);
else if((ind==0 && j==vec[vis[i]][(int)vec[vis[i]].size()-1]) || (ind==(int)vec[vis[i]].size()-1 && j==vec[vis[i]][0]))vv.pb(1);
else vv.pb(0);
}
a.pb(vv);
}
//~ }
build(a);
return 1;
}
# | 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... |