제출 #490274

#제출 시각아이디문제언어결과실행 시간메모리
490274fcmalkcinSplit the Attractions (IOI19_split)C++17
컴파일 에러
0 ms0 KiB
#include <bits/stdc++.h> using namespace std; #define ll int #define pll pair<ll,ll> #define ff first #define ss second #define pb push_back #define endl "\n" //mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count()); const ll maxn=1e5+50; const ll mod=1e9+7 ; const ll base=2e18; /// you will be the best but now you just are trash /// goal 6/7 vector<ll> adj[maxn]; vector<pll> nw; vector<ll> adj1[maxn]; ll siz[maxn]; ll low[maxn]; ll num[maxn]; ll cntnw=0; ll pos=-1; void dfs(ll u) { cntnw++; low[u]=cntnw; num[u]=cntnw; siz[u]=1; bool chk=true; for (auto to:adj[u]) { if (num[to]) { low[u]=min(low[u],num[to]); continue; } adj1[u].pb(to); anc[to]=u; // cout <<u<<" "<<to<<" chk1"<<endl; dfs(to); low[u]=min(low[u],low[to]); siz[u]+=siz[to]; if (siz[to]<nw[0].ff) { } else { chk=false; } } if (chk&&siz[u]>=nw[0].ff) { pos=u; } } vector<ll> ans; ll colmx; ll cnt[4]; ll val[4]; ll dem=0; void dfs1(ll u,ll col1) { // cout <<siz[u]<<" chk"<<endl; if (cnt[col1]<val[col1]) { } else { col1=colmx; } ans[u]=col1; cnt[col1]++; // assert(cnt[col1]<=val[col1]); for (auto to:adj1[u]) { dfs1(to,col1); } } void dfs2(ll u,ll col2) { if (cnt[col2]<val[col2]) { } else { col2=colmx; } ans[u]=col2; cnt[col2]++; // assert(cnt[col2]<=val[col2]); for (auto to:adj[u]) { if (ans[to]) continue; dfs2(to,col2); } } vector<ll> find_split(int n, int a, int b, int c, vector<ll> p, vector<ll> q) { memset(anc,-1,sizeof(anc)); nw.pb(make_pair(a,1)); nw.pb(make_pair(b,2)); nw.pb(make_pair(c,3)); sort(nw.begin(),nw.end()); for (int i=1;i<=nw.size();i++) val[nw[i-1].ss]=nw[i-1].ff; colmx=nw.back().ss; for (int i=0;i<p.size();i++) { adj[p[i]].pb(q[i]); adj[q[i]].pb(p[i]); } ans=vector<ll> (n,0); dfs(0); // cout <<pos<<endl; assert(pos!=-1); ll cl=siz[pos]; ll u=pos; ll h=n-cl; // cout <<h<<" "<<cl<<endl; ll kp=nw[0].ff; for (int i=0;i<adj1[u].size();i++) { ll to=adj1[u][i]; if (to==anc[u]) continue; // cout <<"wTF"<<" "<<to<<" "<<u<<" "<<anc[u]<<endl; if (low[to]<num[u]) { // cout <<"WTF"<<endl; if (cl-siz[to]>=kp) { // cout <<"WYF"<<endl; h+=siz[to]; cl-=siz[to]; } else { // cout <<"nah"<<endl; break; } } else { } } // cout <<h<<" "<<nw[1].ff<<endl; if (h<nw[0].ff) { ans=vector<ll> (n,0); return ans; } // cout <<h<<" "<<cl<<" "<<pos<<" "<<adj1[pos].size()<<" "<<siz[pos]<<endl; if (h<cl) { swap(nw[0],nw[1]); // cout <<"na"<<endl; } cl=siz[pos]; h=n-cl; // cout <<h<<" "<<cl<<endl; ans[pos]=nw[0].ss; cnt[nw[0].ss]++; // cout <<cnt[1]<<" "<<cnt[2]<<" "<<cnt[3]<<endl; for (int i=0;i<adj1[u].size();i++) { ll to=adj1[u][i]; // cout <<"wTF"<<" "<<to<<" "<<u<<" "<<anc[u]<<endl; if (low[to]<num[u]) { // cout <<"WTF"<<endl; if (cl-siz[to]>=kp) { h+=siz[to]; cl-=siz[to]; } else { // cout <<"nah"<<endl; for (int j=i;j<adj1[u].size();j++) { ll to=adj1[u][j]; dfs1(to,nw[0].ss); } break; } } else { //cout <<" wtf"<<endl; dfs1(to,nw[0].ss); } } //cout <<nw[1].ss<<" "<<cnt[2]<<" "<<val[2]<<" "<<cnt[3]<<" "<<val[3]<<endl; if (anc[u]!=-1) { dfs2(anc[u],nw[1].ss); } for (int i=1;i<=3;i++) { // cout <<cnt[i]<<" "<<val[i]<<endl; if (cnt[i]!=val[i]) { cout <<-1; } // assert(cnt[i]==val[i]); // cout <<-1; } // ans=vector<ll> (n,1); return ans; } /*int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); if (fopen("test.inp", "r")) { freopen("test.inp", "r", stdin); // freopen("test.", "w", stdout); } if (1) { ll n, a, b, c; ll m; cin>> n>> m; cin>> a>> b>> c; vector<ll> vt; vector<ll> vt1; for (int i=1;i<=m;i++) { ll x, y; cin>>x>> y; vt.pb(x); vt1.pb(y); } vector<ll> ans=find_split(n,a,b,c, vt,vt1); } else { vector<ll> ans=find_split(3,1,1,1, {0,0},{2,1}); } }*/

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

split.cpp:14:15: warning: overflow in conversion from 'double' to 'int' changes value from '2.0e+18' to '2147483647' [-Woverflow]
   14 | const ll base=2e18;
      |               ^~~~
split.cpp: In function 'void dfs(int)':
split.cpp:40:9: error: 'anc' was not declared in this scope
   40 |         anc[to]=u;
      |         ^~~
split.cpp: In function 'std::vector<int> find_split(int, int, int, int, std::vector<int>, std::vector<int>)':
split.cpp:104:12: error: 'anc' was not declared in this scope; did you mean 'ans'?
  104 |     memset(anc,-1,sizeof(anc));
      |            ^~~
      |            ans
split.cpp:109:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  109 |     for (int i=1;i<=nw.size();i++) val[nw[i-1].ss]=nw[i-1].ff;
      |                  ~^~~~~~~~~~~
split.cpp:111:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  111 |     for (int i=0;i<p.size();i++)
      |                  ~^~~~~~~~~
split.cpp:125:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  125 |     for (int i=0;i<adj1[u].size();i++)
      |                  ~^~~~~~~~~~~~~~~
split.cpp:167:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  167 |     for (int i=0;i<adj1[u].size();i++)
      |                  ~^~~~~~~~~~~~~~~
split.cpp:183:31: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  183 |                 for (int j=i;j<adj1[u].size();j++)
      |                              ~^~~~~~~~~~~~~~~