이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#include "supertrees.h"
using namespace std;
#ifdef LOCAL
#define deb(...) logger(#__VA_ARGS__, __VA_ARGS__)
template<typename ...Args>
void logger(string vars, Args&&... values) {
cerr<<vars<<" = ";
string delim="";
(...,(cerr<<delim<<values,delim=", "));
cerr<<"\n";
}
#else
#define deb(...) logger(#__VA_ARGS__, __VA_ARGS__)
template<typename ...Args>
void logger(string vars, Args&&... values) {}
#endif
#define FOR(i,j,n) for(int i=j;i<n;i++)
#define pb push_back
#define sz(x) (int)(x.size())
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
template<typename T> inline void maxa(T& a,T b){a=max(a,b);}
template<typename T> inline void mina(T& a,T b){a=min(a,b);}
/*
subtask 1: make a line graph
subtask 2: make multiple line graphs, make sure no components have contradictions
subtask 3: make multiple rings, make sure no contradictions
subtask 4: in each component, make components of 2s. Form these into rings. connect the rings.
then get components of ones and make them into line graphs.
subtask 5: subtask 4 and check for contradictions
subtask 6: for the components of 3, make a ring and add an extra edge
rings must have at least 3 nodes
3-rings must have at least 4 nodes
*/
// void build(vector<vector<int>> b){
// int n=sz(b);
// for(int i=0;i<n;i++){
// for(int j=0;j<n;j++){
// cout<<b[i][j]<<" ";
// }
// cout<<"\n";
// }
// }
const int mxN=1e3+5;
int uf[mxN];
int find(int x){return uf[x]<0?x:uf[x]=find(uf[x]);}
bool same(int x,int y){return find(x)==find(y);}
void unite(int x,int y){
x=find(x); y=find(y);
if(x==y)
return;
if(uf[x]>uf[y])
swap(x,y);
uf[x]+=uf[y]; uf[y]=x;
}
int construct(vector<vector<int>> p){
memset(uf,-1,sizeof(uf));
int n=sz(p);
vector<vector<int>> b;
b.resize(n);
for(auto &u:b)
u.resize(n);
for(int i=0;i<n;i++){
for(int j=0;j<n;j++){
if(p[i][j])
unite(i,j);
}
}
for(int i=0;i<n;i++){
for(int j=0;j<n;j++){
if(!p[i][j] && same(i,j))
return 0;
}
}
vector<int> component[n];
for(int i=0;i<n;i++){
component[find(i)].pb(i);
}
for(auto u:component){
if(sz(u)<=1)
continue;
if(sz(u)==2 && p[u[0]][u[1]]==2)
return 0;
for(int i=0;i<sz(u)-1;i++){
b[u[i]][u[i+1]]=b[u[i+1]][u[i]]=1;
}
if(p[u[0]][u[1]]==2)
b[u[0]][u.back()]=b[u.back()][u[0]]=1;
}
build(b);
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... |