Submission #488037

#TimeUsernameProblemLanguageResultExecution timeMemory
488037SlavicGConnecting Supertrees (IOI20_supertrees)C++17
40 / 100
228 ms26192 KiB
#include "supertrees.h" #include "bits/stdc++.h" using namespace std; #define ll long long #define forn(i,n) for(int i=0;i<n;i++) #define all(v) v.begin(), v.end() #define rall(v) v.rbegin(),v.rend() #define pb push_back #define sz(a) (int)a.size() struct DSU{ int n; vector<int> par, s; DSU(int N){ n = N; s.assign(n, 1), par.resize(n); iota(all(par), 0); } int get(int a){ return par[a] = (a == par[a] ? a : get(par[a])); } void uni(int a, int b){ a = get(a), b = get(b); if(s[a] > s[b])swap(a, b); par[a] = b, s[b] += s[a]; } int get_size(int a){ return s[get(a)]; } bool same_set(int a, int b){ return get(a) == get(b); } }; const int N = 1005; vector<int> adj[N], adj2[N]; vector<int> component; bool vis[N]; void dfs(int u){ component.pb(u); vis[u] = true; for(int v: adj[u])if(!vis[v])dfs(v); } int construct(vector<vector<int>> p){ int n = sz(p); vector<vector<int>> ans(n, vector<int>(n, 0)); forn(i,n)adj[i].clear(), adj2[i].clear(); DSU d(n); DSU fuck(n); for(int i = 0;i < n; ++i){ for(int j = 0;j < n; ++j){ if(i == j)continue; if(p[i][j] != p[j][i])return 0; } } for(int i = 0;i < n; ++i){ vis[i] = false; for(int j = 0;j < n; ++j){ if(p[i][j] == 2 && i != j){ adj[i].pb(j); } if(p[i][j] == 1 && i != j){ adj2[i].pb(j); } } } for(int i = 0;i < n; ++i){ if(!vis[i]){ component.clear(); dfs(i); if(sz(component) == 2)return 0; for(int i = 0;i < sz(component); ++i){ if(sz(component) > 1)ans[component[i]][component[(i + 1) % sz(component)]] = ans[component[(i + 1) % sz(component)]][component[i]] = 1; fuck.uni(component[i], component[(i + 1) % sz(component)]); } int prev = -1; for(int u: component){ for(int v: adj2[u]){ if(!d.same_set(u, v)){ ans[u][v] = ans[v][u] = 1; d.uni(u, v); } } prev = u; } } } for(int i = 0;i < n; ++i){ for(int j = 0;j < n; ++j){ if(i == j)continue; if(ans[i][j] && !p[i][j])return 0; if(fuck.same_set(i, j) && !p[i][j])return 0; if(d.same_set(i, j) && !p[i][j])return 0; } } for(int i = 0;i < n; ++i){ adj[i].clear(); adj2[i].clear(); vis[i] = false; } build(ans); return 1; }

Compilation message (stderr)

supertrees.cpp: In function 'int construct(std::vector<std::vector<int> >)':
supertrees.cpp:89:17: warning: variable 'prev' set but not used [-Wunused-but-set-variable]
   89 |             int prev = -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...