Submission #352359

#TimeUsernameProblemLanguageResultExecution timeMemory
352359ryanseeConnecting Supertrees (IOI20_supertrees)C++14
96 / 100
280 ms23404 KiB
#include "supertrees.h" #include "bits/stdc++.h" using namespace std; #define FAST ios_base::sync_with_stdio(false); cin.tie(0); #define pb push_back #define eb emplace_back #define ins insert #define f first #define s second #define cbr cerr<<"hi\n" #define mmst(x, v) memset((x), v, sizeof ((x))) #define siz(x) ll(x.size()) #define all(x) (x).begin(), (x).end() #define lbd(x,y) (lower_bound(all(x),y)-x.begin()) #define ubd(x,y) (upper_bound(all(x),y)-x.begin()) mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); //can be used by calling rng() or shuffle(A, A+n, rng) inline long long rand(long long x, long long y) { return rng() % (y+1-x) + x; } //inclusivesss string inline to_string(char c) {string s(1,c);return s;} template<typename T> inline T gcd(T a,T b){ return a==0?llabs(b):gcd(b%a,a); } using ll=long long; using ld=long double; #define FOR(i,s,e) for(ll i=s;i<=ll(e);++i) #define DEC(i,s,e) for(ll i=s;i>=ll(e);--i) using pi=pair<ll,ll>; using spi=pair<ll,pi>; using dpi=pair<pi,pi>; long long LLINF = 1e18; int INF = 1e9+1e6; #define MAXN (1006) int p[MAXN]; void init() { FOR(i,0,MAXN-1) p[i]=i; } int find(int x) { return p[x] == x ? x : p[x] = find(p[x]); } void merge(int x,int y) { p[find(x)] = find(y); } vector<vector<int>> v; void add(int x,int y) { v[x][y]=v[y][x]=1; } int construct(std::vector<std::vector<int>> p) { int n = p.size(); v.resize(n, vector<int>(n, 0)); init(); FOR(i,0,n-1) FOR(j,i+1,n-1) if(p[i][j]) merge(i, j); FOR(i,0,n-1) FOR(j,i+1,n-1) if(p[i][j]==0 && find(i)==find(j)) return 0; vector<vector<int>> nodes; FOR(i,0,n-1) if(find(i) == i) { nodes.pb({}); FOR(j,0,n-1) if(find(j) == find(i)) { nodes.back().eb(j); } } init(); for(auto i:nodes) { for(auto j:i) for(auto k:i) if(j^k && p[j][k] == 1) merge(j, k); for(auto j:i) for(auto k:i) if(j^k && p[j][k] == 2 && find(j)==find(k)) return 0; bool got3 = 0; for(auto j:i) for(auto k:i) if(p[j][k] == 3) { got3 = 1; } if(got3) { for(auto j:i) for(auto k:i) if(find(j)^find(k) && p[j][k] ^ 3) return 0; } vector<int> tmp; for(auto j:i) if(find(j)==j) tmp.eb(j); if(siz(tmp) == 2 || (got3 && siz(tmp) == 3)) return 0; if(siz(tmp) > 1) FOR(i,0,siz(tmp)-1) add(tmp[i], tmp[(i+1)%siz(tmp)]); if(got3) { add(tmp[0], tmp[2]); } for(auto j:i) if(find(j) ^ j) add(find(j), j); } build(v); 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...