제출 #371093

#제출 시각아이디문제언어결과실행 시간메모리
371093chubyxdxdSplit the Attractions (IOI19_split)C++17
40 / 100
144 ms17644 KiB
#include "split.h" #include <bits/stdc++.h> #define sc second #define ff first using namespace std; typedef pair<int,int> ii; vector<vector<int>> G; vector<int> A; vector<int> B; vector<int> C; int vis[100010]; void dfs(int node,int a,int b,int c){ vis[node]=1; B.push_back(node); if(B.size()==b)return; for(auto i:G[node]){ if(vis[i]==-1){ dfs(i,a,b,c); if(B.size()==b)return; } } } void dfs2(int node,int a,int b,int c){ //cout<<node<<endl; if(A.size()<a){ A.push_back(node); } else{ if(B.size()<b){ B.push_back(node); } else{ C.push_back(node); } } vis[node]=1; for(auto i:G[node]){ //cout<<i<<" "; if(vis[i]==-1){ dfs2(i,a,b,c); } } //cout<<endl; } int sz[100010]; int N; int dfsz(int node,int pad){ sz[node]=1; for(auto i:G[node]){ if(i==pad)continue; sz[node]+=dfsz(i,node); } return sz[node]; } int piv=-1,an=-1; vector<int> ans; void dfsfind(int node,int pad,int a,int b){ //cout<<node<<" "<<sz[node]<<endl; if(sz[node]>=a && N-sz[node]>=b){ piv=node;an=pad; return; } if(sz[node]>=b && N-sz[node]>=a){ piv=pad;an=node; return; } for(auto i:G[node]){ if(i==pad)continue; dfsfind(i,node,a,b); } } int cnt=0; void dfs1(int node,int pad,int a,int col){ cnt++; if(cnt<=a){ ans[node]=col; } for(auto i:G[node]){ if(i==pad)continue; dfs1(i,node,a,col); } } vector<int> find_split(int n, int a, int b, int c, vector<int> p, vector<int> q) { N=n; ans.assign(n,0); vector<ii> v{ii(a,1),ii(b,2),ii(c,3)}; sort(v.begin(),v.end()); G.assign(n+5,vector<int>()); for(int i=0;i<p.size();i++){ G[p[i]].push_back(q[i]); G[q[i]].push_back(p[i]); } if(p.size()==n-1){ int h=dfsz(0,0); dfsfind(0,0,v[0].ff,v[1].ff); if(piv==-1 && an==-1)return ans; cnt=0; //cout<<piv<<" "<<an<<endl; dfs1(piv,an,v[0].ff,v[0].sc); cnt=0; dfs1(an,piv,v[1].ff,v[1].sc); for(int i=0;i<n;i++){ if(ans[i]==0){ ans[i]=v[2].sc; } } return ans; } int piv=0; for(int i=0;i<n;i++){ vis[i]=-1; if(G[i].size()==1)piv=i; } dfs2(piv,a,b,c); for(auto i:A)ans[i]=1; for(auto i:B)ans[i]=2; for(auto i:C)ans[i]=3; return ans; }

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

split.cpp: In function 'void dfs(int, int, int, int)':
split.cpp:15:14: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   15 |   if(B.size()==b)return;
      |      ~~~~~~~~^~~
split.cpp:19:18: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   19 |       if(B.size()==b)return;
      |          ~~~~~~~~^~~
split.cpp: In function 'void dfs2(int, int, int, int)':
split.cpp:25:14: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   25 |   if(A.size()<a){
      |      ~~~~~~~~^~
split.cpp:29:16: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   29 |     if(B.size()<b){
      |        ~~~~~~~~^~
split.cpp: In function 'std::vector<int> find_split(int, int, int, int, std::vector<int>, std::vector<int>)':
split.cpp:89:16: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   89 |   for(int i=0;i<p.size();i++){
      |               ~^~~~~~~~~
split.cpp:93:14: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   93 |   if(p.size()==n-1){
      |      ~~~~~~~~^~~~~
split.cpp:94:8: warning: unused variable 'h' [-Wunused-variable]
   94 |    int h=dfsz(0,0);
      |        ^
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...