이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "split.h"
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
typedef pair<ll,ll> pii;
const ll MAXN = 1e5+5;
const ll INF = 1e9+7;
vector<vector<ll>>adj(MAXN);
int sub[MAXN],cur=1,k,N,chosen=-1,parent;
bool visited[MAXN],fine=true;
vector<int> des(MAXN);
void dfs(ll node, ll p){//cur esta a contar com este
visited[node]=true;
sub[node]=1; if(!fine)return;
bool ok=true;
for(auto u:adj[node]){if(!fine)return;
if(u==p)continue;
dfs(u,node);
sub[node]+=sub[u];
if(sub[u]>=k)ok=false;
}
if(sub[node]>=k&&ok){
chosen=node;
parent=p;
if(N-sub[node]<k){
fine=false;
chosen=-1;
}
}
}
int mark,lim,cont;
void dfs1(ll node, ll p){//cout<<node<<" "<<p<<endl;
des[node]=mark; cont++;
for(auto u:adj[node]){
if(u==p)continue;
//cout<<u<<" "<<node<<" "<<cont<<" "<<lim<<endl;
if(cont+1<=lim){
dfs1(u,node);
}
}
}
vector<int> find_split(int n,int a,int b,int c,vector<int>p,vector<int> q) {
int i,m=p.size(); k=min(min(a,b),c); N=n;
vector<int> res(n);
int meh[3]={a,b,c}; sort(meh,meh+3);
for(i=0;i<m;i++){
adj[p[i]].pb(q[i]);
adj[q[i]].pb(p[i]);
}
for(i=0;i<n;i++)res[i]=0;
dfs(0,-1);
if(chosen==-1)return res;
if(sub[chosen]<n-sub[chosen]){
mark=1; cont=0; lim=meh[0];
dfs1(chosen,parent);
mark=2; cont=0; lim=meh[1];cout<<endl;
dfs1(parent,chosen);
}else{
mark=1; cont=0; lim=meh[0];
dfs1(parent,chosen);
mark=2; cont=0; lim=meh[1];
dfs1(chosen,parent);
}
for(i=0;i<n;i++){
res[i]=des[i];
}
if(a<=b&&b<=c){
for(i=0;i<n;i++){
if(res[i]==0){
res[i]=2;
}
}
}else if(a<=c&&c<=b){
for(i=0;i<n;i++){
if(res[i]==0){
res[i]=2;
}else if(res[i]==2){
res[i]=3;
}
}
}else if(b<=a&&a<=c){
for(i=0;i<n;i++){
if(res[i]==0){
res[i]=3;
}else if(res[i]==1){
res[i]=2;
}else{
res[i]=1;
}
}
}else if(b<=c&&c<=a){
for(i=0;i<n;i++){
if(res[i]==0){
res[i]=1;
}else if(res[i]==1){
res[i]=2;
}else{
res[i]=3;
}
}
}else if(c<=b&&b<=a){
for(i=0;i<n;i++){
if(res[i]==0){
res[i]=1;
}else if(res[i]==1){
res[i]=3;
}else{
res[i]=3;
}
}
}else{//c<=a<=b
for(i=0;i<n;i++){
if(res[i]==0){
res[i]=2;
}else if(res[i]==1){
res[i]=3;
}else{
res[i]=1;
}
}
}
return res;
}
# | 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... |