제출 #893457

#제출 시각아이디문제언어결과실행 시간메모리
893457Jawad_Akbar_JJSplit the Attractions (IOI19_split)C++17
컴파일 에러
0 ms0 KiB
#include <iostream> #include <vector> #include <set> #include <cstring> #include "split.h" #include <algorithm> using namespace std; const int N = 1e5 + 10; vector<vector<int>> v; vector<int> nei[N]; int A,B; int mn[N]; int sz[N]; int hei[N]; bool seen[N]; int color[N]; bool found = false; int K; void dfs_color(int u,int c){ if (seen[u]) return; if (K<=0) return; color[u] = c; seen[u] = true; K--; for (int i : nei[u]){ if (seen[i]) continue; dfs_color(i,c); } } void dfs(int u,int h = 1){ sz[u] = 1; hei[u] = h++; seen[u] = true; mn[u] = hei[u]; for (int i : nei[u]){ if (seen[i]){ mn[u] = min(mn[u],hei[i]); continue; } dfs(i,h); sz[u] += sz[i]; if (mn[i]) mn[u] = min(mn[u],mn[i]); } } // #################################### reset seen bool called = false; void call(int u,set<int> s,int c,int Sz){ if (called) return; called = true; memset(seen,false,sizeof seen); seen[u] = true; color[u] = c; Sz--; K = Sz; for (int i : s) dfs_color(i,c); } void dfs2(int u){ seen[u] = true; int p1 = sz[u]; int p2 = sz[1] - sz[u]; set<int> s; for (int i : nei[u]) if (!seen[i]){ if (found) return; s.insert(i); dfs2(i); } if (p1>=A and p2>=B){ call(u,s,v[0][1],A); K = B; dfs_color(1,v[1][1]); found = true; return; } else if (p1>=B and p2>=A){ call(u,s,v[1][1],B); K = A; dfs_color(1,v[0][1]); found = true; return; } for (int i : nei[u]){ if (seen[i]) continue; if (found) return; if (p1 - sz[i] >= A and mn[i] < hei[u]){ s.erase(i); p1 -= sz[i]; p2 += sz[i]; } if (p1>=A and p2>=B){ call(u,s,v[0][1],A); K = B; dfs_color(1,v[1][1]); found = true;1 return; } else if (p1>=B and p2>=A){ call(u,s,v[1][1],B); K = A; dfs_color(1,v[0][1]); found = true; return; } } } vector<int> find_split(int n,int a,int b,int c,vector<int> p,vector<int> q){ int m = p.size(); for (int i=0;i<m;i++){ p[i]++; q[i]++; nei[p[i]].push_back(q[i]); nei[q[i]].push_back(p[i]); } v.push_back({a,1}); v.push_back({b,2}); v.push_back({c,3}); sort(begin(v),end(v)); A = v[0][0]; B = v[1][0]; dfs(1,1); memset(seen,false,sizeof seen); dfs2(1); vector<int> col; if (!found){ for (int i=1;i<=n;i++) col.push_back(0); return col; } for (int i=1;i<=n;i++){ if (color[i]==0) col.push_back(v[2][1]); else col.push_back(color[i]); } return col; }

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

split.cpp: In function 'void dfs2(int)':
split.cpp:115:18: error: expected ';' before 'return'
  115 |    found = true;1
      |                  ^
      |                  ;
  116 |    return;
      |    ~~~~~~         
split.cpp:115:17: warning: statement has no effect [-Wunused-value]
  115 |    found = true;1
      |                 ^