Submission #366766

#TimeUsernameProblemLanguageResultExecution timeMemory
366766SlavicGConnecting Supertrees (IOI20_supertrees)C++17
40 / 100
295 ms26348 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() #define fastio ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0); const int N = 1001; vector<int> adj[N]; bool vis[N]; set<int> n2; bool two_cur; vector<int> component; int par[N]; int get(int a){ while(par[a]!=a)a=par[a]; return a; } void uni(int a,int b){ a = get(a); b = get(b); if(a==b)return; par[b] = a; } void dfs(int u) { vis[u] = true; if(n2.count(u))two_cur = true; component.pb(u); for(auto x : adj[u]){ if(!vis[x])dfs(x); } } int construct(vector<vector<int>> p) { int n = sz(p); vector<vector<int>> ans; ans.resize(n); for(int i=0;i < n;i++) par[i]=i; for(int i =0;i < n;i++)ans[i].resize(n); forn(i,n)forn(j,n)ans[i][j]=0; bool two = false; bool one = false; for(int i = 0;i < n;i++) { for(int j = 0;j < n;j++) { if(p[i][j]==2)two=true; if(p[i][j] == 1)one = true; if(p[i][j]){ uni(i,j); adj[i].pb(j); } } } for(int i = 0;i < n;i++) { for(int j =0;j < n;j++) { if(get(i)==get(j) && !p[i][j])return 0; } } for(int i = 0;i < n;i++) { for(int j = 0;j < n;j++) { if(p[i][j] == 2)n2.insert(i); } } for(int i = 0;i < n;i++) { if(!vis[i]){ component.clear(); two_cur = false; dfs(i); if(sz(component) == 2 && two_cur)return 0; for(int j = 1;j < sz(component);j++) { ans[component[j]][component[j-1]] = ans[component[j-1]][component[j]] = 1; } if(two_cur && sz(component) > 1)ans[component.back()][component[0]] = ans[component[0]][component.back()] = 1; } } build(ans); return 1; }

Compilation message (stderr)

supertrees.cpp: In function 'int construct(std::vector<std::vector<int> >)':
supertrees.cpp:52:7: warning: variable 'two' set but not used [-Wunused-but-set-variable]
   52 |  bool two = false;
      |       ^~~
supertrees.cpp:53:7: warning: variable 'one' set but not used [-Wunused-but-set-variable]
   53 |  bool one = false;
      |       ^~~
#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...