Submission #348879

#TimeUsernameProblemLanguageResultExecution timeMemory
348879justiny7슈퍼트리 잇기 (IOI20_supertrees)C++14
Compilation error
0 ms0 KiB
#include "supertrees.h" #include <bits/stdc++.h> #define eb emplace_back using namespace std; using vi=vector<int>; using vvi=vector<vi>; const int mxN=1e3+1; int n; vvi ans; struct DSU { int par[mxN], sz[mxN]; DSU(int n) { for (int i=0; i<n; ++i) par[i]=i, sz[i]=1; } int find(int v) { return (par[v]==v?v:par[v]=find(par[v])); } bool merge(int a, int b) { a=find(a), b=find(b); if (a==b) return 0; if (sz[a]>sz[b]) swap(a, b); par[a]=b, sz[b]+=sz[a]; return 1; } bool same(int a, int b) { return (find(a)==find(b)); } }; bool subtask_3(vvi &p) { DSU d(n); bool f=0; for (int i=0; i<n; ++i) for (int j=0; j<n; ++j) if (p[i][j]) d.merge(i, j), f|=(p[i][j]==2); for (int i=0; i<n; ++i) for (int j=0; j<n; ++j) if (!p[i][j] && d.same(i, j)) return 0; vector<bool> vis(n); for (int i=0; i<n; ++i) { if (vis[d.find(i)]) continue; vis[d.find(i)]=1; vi here; for (int j=0; j<n; ++j) here.eb(j); int sz=here.size(); for (int j=0; j<sz; ++j) { if (j) ans[v[j]][v[j-1]]=ans[v[j-1]][v[j]]=1; if (j<sz-1) ans[v[j]][v[j+1]]=ans[v[j+1]][v[j]]=1; } if (f) { if (sz>2) ans[v[0]][v.back()]=ans[v.back()][v[0]]=1; else if (sz==2) return 0; } } return 1; } int construct(vvi p) { n=p.size(); ans=vvi(n, vi(n)); bool f0=0, f1=0, f2=0, f3=0; for (int i=0; i<n; ++i) { for (int j=0; j<n; ++j) { if (i==j) continue; f0|=(!p[i][j]); f1|=(p[i][j]==1); f2|=(p[i][j]==2); f3|=(p[i][j]==3); } } if (!f3 && !(f1 && f2)) { if (subtask_3(p)) { build(ans); return 1; } return 0; } }

Compilation message (stderr)

supertrees.cpp: In function 'bool subtask_3(vvi&)':
supertrees.cpp:57:21: error: 'v' was not declared in this scope
   57 |                 ans[v[j]][v[j-1]]=ans[v[j-1]][v[j]]=1;
      |                     ^
supertrees.cpp:59:21: error: 'v' was not declared in this scope
   59 |                 ans[v[j]][v[j+1]]=ans[v[j+1]][v[j]]=1;
      |                     ^
supertrees.cpp:63:21: error: 'v' was not declared in this scope
   63 |                 ans[v[0]][v.back()]=ans[v.back()][v[0]]=1;
      |                     ^
supertrees.cpp: In function 'int construct(vvi)':
supertrees.cpp:92:1: warning: control reaches end of non-void function [-Wreturn-type]
   92 | }
      | ^