제출 #1065960

#제출 시각아이디문제언어결과실행 시간메모리
1065960epicci23열쇠 (IOI21_keys)C++17
컴파일 에러
0 ms0 KiB
#include "bits/stdc++.h" #define all(v) v.begin() , v.end() #define sz(a) (int)a.size() using namespace std; const int N = 3e5 + 5; map<int,vector<int>> v[N]; set<int> s[N]; vector<int> cur,par(N,0),vis(N,0),mark(N,0); vector<int> comp[N]; void merge_info(int a,int b){ a=par[a],b=par[b]; if(a==b) return; mark[a]|=mark[b]; if(sz(s[a])<sz(s[b])) swap(s[a],s[b]); if(sz(comp[a])<sz(comp[b])) swap(comp[a],comp[b]); for(int x:comp[b]){ comp[a].push_back(x); par[x]=a; } comp[b].clear(); for(int u:s[b]) s[a].insert(u); s[b].clear(); int sA=0,sB=0; for(auto x:v[a]) sA+=sz(x.second); for(auto x:v[b]) sB+=sz(x.second); if(sA<sB) swap(v[a],v[b]); for(auto x:v[b]) for(int u:x.second) v[a][x.first].push_back(u); v[b].clear(); } void dfs(int c){ if(vis[c]) return; cur.push_back(c); vis[c]=1; for(int u:s[par[c]]){ while(!v[par[c]][u].empty()){ int x=v[par[c]][u].back(); v[par[c]][u].pop_back(); if(x==par[c]) continue; if(vis[x]==2){ mark[par[c]]=1; continue; } if(vis[x]==1){ while(!cur.empty() && par[cur.back()]!=par[x]){ merge_info(cur.back(),x); cur.pop_back(); } } else{ dfs(x); if(par[c]!=par[x]) mark[par[c]]=1; } } } if(!cur.empty() && cur.back()==c) cur.pop_back(); vis[c]=2; } vector<int> find_reachable(vector<int> R, vector<int> U, vector<int> V, vector<int> C){ int n=sz(R),m=sz(U); iota(all(par),0); for(int i=0;i<n;i++) comp[i].push_back(i); for(int i=0;i<n;i++) s[i].insert(R[i]); for(int i=0;i<m;i++){ int a=U[i],b=V[i],c=C[i]; v[a][c].push_back(b); v[b][c].push_back(a); } for(int i=0;i<n;i++) if(vis[i]==0) dfs(i); int mini=100000007; for(int i=0;i<n;i++){ if(mark[dsu.find(i)]) continue; mini=min(mini,dsu.siz[dsu.find(i)]); } vector<int> ans(n,0); for(int i=0;i<n;i++) if(!mark[dsu.find(i)] && dsu.siz[dsu.find(i)]==mini) ans[i]=1; return ans; } /*void _(){ int n,m; cin >> n >> m; iota(all(par),0); for(int i=0;i<n;i++) comp[i].push_back(i); vector<int> col(n); for(int i=0;i<n;i++) cin >> col[i]; for(int i=0;i<n;i++) s[i].insert(col[i]); for(int i=0;i<m;i++){ int a,b,c; cin >> a >> b >> c; v[a][c].push_back(b); v[b][c].push_back(a); } for(int i=0;i<n;i++) if(vis[i]==0) dfs(i); int mini=100000007; for(int i=0;i<n;i++){ if(mark[dsu.find(i)]) continue; mini=min(mini,dsu.siz[dsu.find(i)]); } vector<int> ans(n,0); for(int i=0;i<n;i++) if(!mark[dsu.find(i)] && dsu.siz[dsu.find(i)]==mini) ans[i]=1; for(int i=0;i<n;i++) cout << ans[i] << " \n"[i==n-1]; } int32_t main(){ cin.tie(0); ios::sync_with_stdio(0); int tc=1;//cin >> tc; while(tc--) _(); return 0; }*/

컴파일 시 표준 에러 (stderr) 메시지

keys.cpp: In function 'std::vector<int> find_reachable(std::vector<int>, std::vector<int>, std::vector<int>, std::vector<int>)':
keys.cpp:75:13: error: 'dsu' was not declared in this scope
   75 |     if(mark[dsu.find(i)]) continue;
      |             ^~~
keys.cpp:76:19: error: 'dsu' was not declared in this scope
   76 |     mini=min(mini,dsu.siz[dsu.find(i)]);
      |                   ^~~
keys.cpp:79:33: error: 'dsu' was not declared in this scope
   79 |   for(int i=0;i<n;i++) if(!mark[dsu.find(i)] && dsu.siz[dsu.find(i)]==mini) ans[i]=1;
      |                                 ^~~