Submission #359294

#TimeUsernameProblemLanguageResultExecution timeMemory
359294ljubaConnecting Supertrees (IOI20_supertrees)C++17
100 / 100
285 ms28288 KiB
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef long double ld; typedef vector<int> vi; typedef vector<ll> vll; typedef vector<vi> vvi; typedef vector<vll> vvll; typedef pair<int, int> pii; typedef pair<ll, ll> pll; typedef vector<pii> vpii; typedef vector<pll> vpll; typedef vector<vpii> vvpii; typedef vector<vpll> vvpll; #define pb push_back #define mp make_pair #define all(x) (x).begin(), (x).end() #define rall(x) (x).rbegin(), (x).rend() #define sz(x) (int)(x).size() #define fi first #define se second template<class T> bool ckmin(T &a, const T &b) {return a > b ? a = b, 1 : 0;} template<class T> bool ckmax(T &a, const T &b) {return a < b ? a = b, 1 : 0;} void __print(int x) {cerr << x;} void __print(long long x) {cerr << x;} void __print(double x) {cerr << x;} void __print(long double x) {cerr << x;} void __print(char x) {cerr << '\'' << x << '\'';} void __print(const string &x) {cerr << '\"' << x << '\"';} void __print(bool x) {cerr << (x ? "true" : "false");} template<typename T, typename V> void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';} template<typename T> void __print(const T &x) {int f = 0; cerr << '{'; for(auto z : x) cerr << (f++ ? "," : ""), __print(z); cerr << "}";} void _print() {cerr << "]\n";} template <typename T, typename... V> void _print(T t, V... v) {__print(t); if(sizeof...(v)) cerr << ", "; _print(v...);} #ifdef ljuba #define dbg(x...) cerr << "LINE(" << __LINE__ << ") -> " << "[" << #x << "] = ["; _print(x) #else #define dbg(x...) #endif const char nl = '\n'; #include "supertrees.h" const int mxN = 1005; bool vis[mxN]; int n; vi cur; vvi p; vvi ans; struct DSU { int rod[mxN], vel[mxN]; DSU() { for(int i = 0; i < mxN; ++i) { rod[i] = i; vel[i] = 1; } } int find_set(int a) { if(a == rod[a]) return a; return rod[a] = find_set(rod[rod[a]]); } bool unite(int a, int b) { a = find_set(a); b = find_set(b); if(a == b) return 0; if(vel[a] > vel[b]) swap(a, b); vel[b] += vel[a]; rod[a] = b; return 1; } }dsu; void dfs(int s) { cur.pb(s); dbg(s); vis[s] = 1; for(int i = 0; i < n; ++i) { if(!vis[i] && p[s][i]) dfs(i); } } bool idi(int s) { cur.clear(); dfs(s); for(auto z : cur) { for(auto z2 : cur) { if(!p[z][z2]) return 0; } } //resenje bi trebalo da izgleda kao da dole imas lance, a iznad lanaca jos dva cvora tako da su oba povezana sa pocetkom svih lanaca vi lanac; dbg(cur); for(auto z : cur) { if(dsu.find_set(z) == z) { lanac.pb(z); vi comp; for(int i = 0; i < n; ++i) { if(dsu.find_set(i) == z) { comp.pb(i); } } dbg(comp); for(int i = 0; i + 1 < sz(comp); ++i) { ans[comp[i]][comp[i+1]] = ans[comp[i+1]][comp[i]] = 1; } for(auto z : comp) { for(auto z2 : comp) if(p[z][z2] != 1) return 0; } } } dbg(lanac); if(sz(lanac) == 2) return 0; if(sz(lanac) == 1) return 1; for(int i = 0; i < sz(lanac); ++i) { ans[lanac[i]][lanac[(i+1)%sz(lanac)]] = ans[lanac[(i+1)%sz(lanac)]][lanac[i]] = 1; } return 1; } int construct(vvi p2) { p = p2; n = sz(p); ans = vvi(n, vi(n, 0)); for(int i = 0; i < n; ++i) { for(int j = 0; j < n; ++j) { if(p[i][j] == 3) return 0; } } for(int i = 0; i < n; ++i) { for(int j = 0; j < n; ++j) { if(p[i][j] == 1) dsu.unite(i, j); } } for(int i = 0; i < n; ++i) { if(!vis[i]) { if(!idi(i)) return 0; } } dbg(ans); 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...