이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "split.h"
#include<bits/stdc++.h>
using namespace std;
using lli=long long int;
#define pb push_back
#define deb(x) cout<<#x<<": "<<x<<endl;
vector<int> ans;
vector<bool> visited;
void dfs(int x, vector<vector<int>>& adj, int &cont, int &a, int &b, int &c){
if(cont<a){
ans[x]=1;
}
else if(cont<a+b){
ans[x]=2;
}
else ans[x]=3;
for(int y: adj[x]){
if(visited[y]) continue;
visited[y]=true;
cont++;
dfs(y, adj,cont,a,b,c);
}
}
vector<vector<int>> sons;
vector<int> sz;
void dfs2(int x, int p, vector<vector<int>> &adj){
sz[x]++;
for(int y: adj[x]){
if(y==p) continue;
sons[x].pb(y);
dfs2(y,x,adj);
sz[x]+=sz[y];
}
}
vector<int> v1;
vector<int> v2;
void dfs3(int x, int &a, int &b, int s, bool ya, bool whch){
if(ya){
v1.pb(x);
for(int y:sons[x]){
dfs3(y,a,b,s,ya,whch);
}
}
else{
if(x==s){
dfs3(x,a,b,s,1,whch);
return;
}
v2.pb(x);
for(int y:sons[x]){
dfs3(y,a,b,s,ya,whch);
}
}
}
vector<int> find_split(int n, int a1, int b1, int c1, vector<int> p, vector<int> q) {
int m=p.size();
if(m==n-1){
vector<pair<int,int>> ayuda;
ayuda.pb({a1,1});
ayuda.pb({b1,2});
ayuda.pb({c1,3});
sort(ayuda.begin(), ayuda.end());
int a=ayuda[0].first;
int b=ayuda[1].first;
int c=ayuda[2].first;
ans.clear();
sons.clear();
sz.clear();
// visited.clear();
ans.resize(n,ayuda[2].second);
// visited.resize(n,0);
//visited[0]=true;
sons.resize(n);
sz.resize(n,0);
vector<vector<int>> adj(n);
for(int i=0; i<p.size(); ++i){
adj[p[i]].pb(q[i]);
adj[q[i]].pb(p[i]);
}
dfs2(0,-1,adj);
lli si0=-1;
lli si1=-1;
for(lli i=0; i<n; ++i){
// deb(sz[i]);
if(sz[i]>=a && n-sz[i]>=b) si0=i;
if(sz[i]>=b && n-sz[i]>=a) si1=i;
}
// deb(si0);
// deb(si1);
// si0=-1;
if(si0!=-1){
dfs3(0,a,b,si0,0,0);
for(int i=0; i<a; ++i){
ans[v1[i]]=ayuda[0].second;
}
for(int i=0; i<b; ++i){
ans[v2[i]]=ayuda[1].second;
}
return ans;
}
if(si1!=-1){
dfs3(0,a,b,si1,0,1);
for(int i=0; i<b; ++i){
ans[v1[i]]=ayuda[1].second;
}
for(int i=0; i<a; ++i){
ans[v2[i]]=ayuda[0].second;
}
return ans;
}
vector<int> mqm(n,0);
return mqm;
}
else{
ans.clear();
visited.clear();
ans.resize(n,0);
visited.resize(n,0);
//visited[0]=true;
int cont=0;
vector<vector<int>> adj(n);
for(int i=0; i<p.size(); ++i){
adj[p[i]].pb(q[i]);
adj[q[i]].pb(p[i]);
}
int x=0;
int gradoact=INT_MAX;
for(int i=0; i<n; ++i){
if(adj[i].size()<gradoact){
x=i;
gradoact=adj[i].size();
}
}
visited[x]=1;
dfs(x,adj,cont,a1,b1,c1);
return ans;
}
}
컴파일 시 표준 에러 (stderr) 메시지
split.cpp: In function 'std::vector<int> find_split(int, int, int, int, std::vector<int>, std::vector<int>)':
split.cpp:88:17: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
88 | for(int i=0; i<p.size(); ++i){
| ~^~~~~~~~~
split.cpp:76:7: warning: unused variable 'c' [-Wunused-variable]
76 | int c=ayuda[2].first;
| ^
split.cpp:136:16: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
136 | for(int i=0; i<p.size(); ++i){
| ~^~~~~~~~~
split.cpp:143:19: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
143 | if(adj[i].size()<gradoact){
| ~~~~~~~~~~~~~^~~~~~~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |