제출 #678808

#제출 시각아이디문제언어결과실행 시간메모리
678808penguin133슈퍼트리 잇기 (IOI20_supertrees)C++17
21 / 100
195 ms24084 KiB
#include <bits/stdc++.h> #include "supertrees.h" using namespace std; //#define int long long #define pi pair<int, int> #define pii pair<int, pi> #define fi first #define se second #ifdef _WIN32 #define getchar_unlocked _getchar_nolock #endif int par[1005]; int getr(int x){ return (par[x] == x ? x : par[x] = getr(par[x])); } void merge(int a, int b){ a = getr(a), b = getr(b); if(a != b)par[b] = a; } int construct(std::vector<std::vector<int>> p) { int n = p.size(); for(int i=0;i<n;i++)par[i] = i; std::vector<std::vector<int>> ans; for (int i = 0; i < n; i++) { std::vector<int> row(n, 0); ans.push_back(row); } for(int i=0;i<n;i++){ for(int j=0;j<n;j++){ if(p[i][j])merge(i, j); } } for(int i=0;i<n;i++){ for(int j=0;j<n;j++){ if(!p[i][j] && getr(i) == getr(j))return 0; } } for(int i=0;i<n;i++){ vector<int> pos; for(int j=0;j<n;j++)if(getr(j) == i)pos.push_back(j); for(int j=0;j<(int)pos.size() - 1;j++){ ans[pos[j]][pos[j+1]] = 1; ans[pos[j+1]][pos[j]] = 1; } } build(ans); return 1; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...