제출 #1176865

#제출 시각아이디문제언어결과실행 시간메모리
117686512345678Split the Attractions (IOI19_split)C++17
컴파일 에러
0 ms0 KiB
#include "split.h" #include <bits/stdc++.h> using namespace std; const int nx=2e5+5; int sz[nx], used[nx], c, h[nx], szc[nx], cnt; vector<pair<int, int>> d[nx], t; vector<int> res; pair<int, int> mx; int dfssz(int u) { sz[u]=1; for (auto [v, idx]:d[u]) { if (sz[v]) continue; used[idx]=1; sz[u]+=dfssz(v); } return sz[u]; } void dfsfill(int u, int p, int hd) { h[u]=hd; szc[hd]++; for (auto [v, idx]:d[u]) if (v!=p&&used[idx]) dfsfill(v, u, hd); } void fillans(int u, int p, int ans) { if (cnt==0) return; res[u]=ans; cnt--; for (auto [v, idx]:d[u]) if (used[idx]&&v!=p&&v!=c) fillans(v, u, ans); } int findcentroid(int u, int p, int rtsz) { for (auto [v, idx]:d[u]) if (used[idx]&&v!=p&&2*sz[v]>rtsz) return findcentroid(v, u, rtsz); return u; } vector<int> find_split(int n, int a, int b, int c, vector<int> p, vector<int> q) { res.resize(n); t.push_back({a, 1}); t.push_back({b, 2}); t.push_back({c, 3}); sort(t.begin(), t.end()); for (int i=0; i<p.size(); i++) d[p[i]].push_back({q[i], i}), d[q[i]].push_back({p[i], i}); dfssz(1); for (int i=0; i<p.size(); i++) if (!used[i]) return 1/0; c=findcentroid(1, 1, n); for (auto [v, idx]:d[c]) { if (!used[idx]) continue; dfsfill(v, c, v); mx=max(mx, {szc[v], v}); } if (mx.first>=t[0].first) { cnt=t[0].first; fillans(mx.second, c, t[0].second); cnt=t[1].first; fillans(c, c, t[1].second); for (int i=0; i<n;i ++) if (!res[i]) res[i]=t[2].second; return res; } return res; }

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

split.cpp: In function 'std::vector<int> find_split(int, int, int, int, std::vector<int>, std::vector<int>)':
split.cpp:54:58: warning: division by zero [-Wdiv-by-zero]
   54 |     for (int i=0; i<p.size(); i++) if (!used[i]) return 1/0;
      |                                                         ~^~
split.cpp:54:58: error: could not convert '(1 / 0)' from 'int' to 'std::vector<int>'
   54 |     for (int i=0; i<p.size(); i++) if (!used[i]) return 1/0;
      |                                                         ~^~
      |                                                          |
      |                                                          int