Submission #799302

#TimeUsernameProblemLanguageResultExecution timeMemory
799302jlallas384Parachute rings (IOI12_rings)C++17
Compilation error
0 ms0 KiB
#include <bits/stdc++.h> using namespace std; struct ufds{ vector<int> sz, par; ufds(){} ufds(int n): sz(n, 1), par(n){ iota(par.begin(), par.end(), 0); } int find(int a){ return par[a] == a ? a : par[a] = find(par[a]); } int unite(int a, int b){ a = find(a), b = find(b); if(a == b) return 0; if(sz[a] < sz[b]) swap(a, b); par[b] = a; sz[a] += sz[b]; return 1; } }; set<int> ans; vector<vector<int>> g, tree; vector<int> deg; int n; ufds ds; int bad = 0; int d4 = 0; void Init(int N){ n = N; g.resize(n); tree.resize(n); deg.resize(n); for(int i = 0; i < n; i++){ ans.insert(i); } ds = ufds(n); } void proc(int a, int add = 1){ if(deg[a] == 4){ if(add){ d4++; if(d4 == 2) bad = 1; } if(!ans.count(a)) ans = {}; else ans = {a}; }else if(deg[a] == 3){ set<int> nans; if(ans.count(a)) nans.insert(a); for(int u: g[a]){ if(ans.count(u)) nans.insert(u); } ans = nans; } } int CountCritical(){ for(int i = 0; i < n; i++){ proc(i, 0); } if(bad) return 0; else return ans.size(); } int cyc = 0; vector<int> path; int dfs(int v, int p, int x){ path.push_back(v); if(v == x) return 1; for(int u: tree[v]) if(u != p){ if(dfs(u, v, x)) return 1; } path.pop_back(); return 0; } void dfs2(int v, set<int> &vis){ if(ans.count(v)) return; vis.insert(v); for(int u: g[v]) if(!vis.count(u)){ dfs2(u, vis); } } int dfs3(int v, set<int> &v1, set<int> &v2){ if(ans.count(v)) return 0; if(v1.count(v)) return 1; v2.insert(v); for(int u: g[v]) if(!v2.count(u)){ if(dfs3(u, v1, v2)) return 1; } return 0; } int dfs4(int v, int p, vector<int> &vis){ vis[v] = 2; for(int u: g[v]){ if(!vis[u] && dfs(u, v, vis)) return 1; else if(vis[u] == 2 && u != p) return 1; } return 0; } void Link(int a, int b){ if(bad) return; int res = ds.unite(a, b); deg[a]++, deg[b]++; g[a].push_back(b); g[b].push_back(a); proc(a), proc(b); if(!res){ if(!cyc){ dfs(a, -1, b); ans = {}; for(int x: path){ ans.insert(x); } for(int i = 0; i < n; i++){ proc(i, 0); } cyc = 1; }else{ if(ans.size() >= 3) bad = 1; g[a].pop_back(); g[b].pop_back(); set<int> v1, v2; dfs2(a, v1); if(dfs3(b, v1, v2)){ bad = 1; } g[a].push_back(b); g[b].push_back(a); if(!bad){ for(int x: ans){ vector<int> vis(n); vis[x] = 1; for(int i = 0; i < n; i++) if(!vis[i]){ assert(!dfs(i, -1, vis)); } } } } }else{ tree[a].push_back(b); tree[b].push_back(a); } }

Compilation message (stderr)

rings.cpp: In function 'int dfs4(int, int, std::vector<int>&)':
rings.cpp:108:33: error: cannot convert 'std::vector<int>' to 'int'
  108 |         if(!vis[u] && dfs(u, v, vis)) return 1;
      |                                 ^~~
      |                                 |
      |                                 std::vector<int>
rings.cpp:77:27: note:   initializing argument 3 of 'int dfs(int, int, int)'
   77 | int dfs(int v, int p, int x){
      |                       ~~~~^
In file included from /usr/include/c++/10/cassert:44,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:33,
                 from rings.cpp:1:
rings.cpp: In function 'void Link(int, int)':
rings.cpp:148:44: error: cannot convert 'std::vector<int>' to 'int'
  148 |                         assert(!dfs(i, -1, vis));
      |                                            ^~~
      |                                            |
      |                                            std::vector<int>
rings.cpp:77:27: note:   initializing argument 3 of 'int dfs(int, int, int)'
   77 | int dfs(int v, int p, int x){
      |                       ~~~~^