제출 #406148

#제출 시각아이디문제언어결과실행 시간메모리
406148ngraceSplit the Attractions (IOI19_split)C++14
0 / 100
195 ms14212 KiB
#include "split.h" #include <bits/stdc++.h> using namespace std; vector<vector<pair<int,int>>> adj; vector<bool> vis; int dfs(int cur){//on tree if(vis[cur]){ return 0; } vis[cur]=true; int ret=0; for(pair<int,int>& it:adj[cur]){ int sub=dfs(it.first); ret+=sub; it.second=sub; } return ret+1; } vector<int> find_split(int n, int a, int b, int c, vector<int> p, vector<int> q) { adj=vector<vector<pair<int,int>>>(n); for(int i=0;i<p.size();i++){ adj[p[i]].push_back({q[i],-1}); adj[q[i]].push_back({p[i],-1}); } vis=vector<bool>(n); dfs(0); vector<int> answer(n,0); bool done=false; for(int i=0;i<p.size();i++){ for(pair<int,int> it:adj[i]){ int prim=-1,sec=-1,spare=-1; if(it.second>=a){ if(n-it.second>=b){ prim=1; sec=2; spare=3; } else if(n-it.second>=c){ prim=1; sec=3; spare=2; } } else if(it.second>=b){ if(n-it.second>=a){ prim=2; sec=1; spare=3; } else if(n-it.second>=c){ prim=2; sec=3; spare=1; } } else if(it.second>=c){ if(n-it.second>=a){ prim=3; sec=1; spare=2; } else if(n-it.second>=b){ prim=3; sec=2; spare=1; } } if(prim!=-1){ done=true; int primC=(prim==1)?a:((prim==2)?b:c); int secC=(sec==1)?a:((sec==2)?b:c); vis=vector<bool>(n,false); stack<int> s; vis[i]=true; s.push(it.first); while(s.size()>0){ int cur=s.top(); s.pop(); if(!vis[cur]){ vis[cur]=true; if(primC>0){ primC--; answer[cur]=prim; } else{ answer[cur]=spare; } for(pair<int,int> pt:adj[cur]){ s.push(pt.first); } } } vis=vector<bool>(n,false); vis[it.first]=true; s.push(i); while(s.size()>0){ int cur=s.top(); s.pop(); if(!vis[cur]){ vis[cur]=true; if(secC>0){ secC--; answer[cur]=sec; } else{ answer[cur]=spare; } for(pair<int,int> pt:adj[cur]){ s.push(pt.first); } } } } if(done){ break; } } if(done){ break; } } return answer; }

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

split.cpp: In function 'std::vector<int> find_split(int, int, int, int, std::vector<int>, std::vector<int>)':
split.cpp:25:15: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   25 |  for(int i=0;i<p.size();i++){
      |              ~^~~~~~~~~
split.cpp:34:15: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   34 |  for(int i=0;i<p.size();i++){
      |              ~^~~~~~~~~
#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...