# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
301173 | M4mou | Connecting Supertrees (IOI20_supertrees) | C++17 | 0 ms | 0 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
#define mp make_pair
#define pb push_back
#define all(x) x.begin(), x.end()
#define fi first
#define se second
#define inf 1000000000
#define sz(x) (ll)x.size()
#define boost ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
typedef long long ll;
typedef unsigned long long ull;
typedef double ld;
typedef vector<int> vi;
typedef pair<int,int> pii;
typedef pair< int , pii> piii;
typedef pair<int,bool> pib;
typedef vector<pii> vii;
typedef vector<pib> vib;
typedef vector<vi> vvi;
typedef vector<vii> vvii;
typedef vector<string> vs;
typedef vector<ll> vll;
typedef pair<string,string> pss;
typedef vector<pss> vss;
typedef pair<ld , ld> pdd;
typedef vector<ld> vd;
typedef vector<vector<pib>> vvib;
typedef vector<piii> viii;
typedef vector<viii> vviii;
typedef vector<bool> vb;
typedef pair<pii , bool> piib;
typedef vector<pair<pii , bool>> viib;
const int MOD = 1e9 + 7; //998244353;
const int MAXN = 100005;
int n;
struct UnionFind{
public:
vi par;
UnionFind(){
for(int i = 0;i<n;i++)par[i] = i;
}
int findset(int x){
if(par[x] == x)return x;
return par[x] = findset(par[x]);
}
void Union(int x , int y){
x = findset(x);
y = findset(y);
if(x != y){
par[x] = y;
}
}
};
UnionFind components();
UnionFind branches();
vvi ans;
bool v[1005];
int construct(vvi p){
n = p.size();
ans.assign(n ,vi(n ,0));
memset(v , 0 , 1005);
for(int i = 0;i<n;i++){
for(int j = 0;j<n;j++){
if(p[i][j] == 3)return 0;
if(p[i][j] >= 1)components().Union(i, j);
if(p[i][j] == 1)branches().Union(i,j);
}
}
for(int i = 0;i<n;i++){
for(int j = 0;j<n;j++){
if(p[i][j] == 0){
if(components().findset(i) == components().findset(j))return 0;
}
if(p[i][j] == 2 && branches().findset(i) == branches().findset(j))return 0;
}
}
for(int i = 0;i<n;i++){
int x = branches().findset(i);
if(v[x])continue;
vi res;
for(int j = 0;j<n;j++){
if(branches().findset(j) == x)res.pb(j);
}
v[x] = 1;
if(res.size() <= 1)continue;
for(int j = 0;j<res.size()-1;j++){
ans[res[j]][res[j+1]] = 1;
ans[res[j+1]][res[j]] = 1;
}
}
memset(v , 0 , 1005);
for(int i = 0;i<n;i++){
int x = components().findset(i);
if(v[x])continue;
v[x] = 1;
vi res;
for(int j = 0;j<n;j++){
int y = branches().findset(j);
if(components().findset(y) == x)res.pb(y);
}
if(res.size() <= 1)continue;
for(int j = 0;j<res.size()-1;j++){
ans[res[j]][res[j+1]] = 1;
ans[res[j+1]][res[j]] = 1;
}
ans[res.front()][res.back()] = 1;
ans[res.back()][res.front()] = 1;
}
build(ans);
return 1;
}
//NEVER GIVE UP
//LONG LONG