이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
/*#pragma GCC optimize("Ofast")
#pragma GCC optimization("unroll-loops, no-stack-protector")
#pragma GCC target("avx,avx2,fma")*/
#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=2e5+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;
ll anc[maxn];
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);
adj1[to].pb(u);
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];
void dfs1(ll u,ll col1)
{
if (cnt[col1]<val[col1])
{
}
else
{
col1=colmx;
}
ans[u]=col1;
cnt[col1]++;
// assert(cnt[col1]<=val[col1]);
for (auto to:adj1[u])
{
if (to==anc[u]||ans[to]) continue;
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:adj1[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;
ans[pos]=nw[0].ss;
cnt[nw[0].ss]++;
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]>=nw[0].ff)
{
h+=siz[to];
cl-=siz[to];
dfs1(to,nw[1].ss);
}
else
{
// cout <<"nah"<<endl;
for (auto to:adj1[u])
{
if (to==anc[u]||ans[to]) continue;
dfs1(to,nw[0].ss);
}
break;
}
}
else
{
dfs1(to,nw[0].ss);
}
}
// cout <<h<<" "<<nw[1].ff<<endl;
if (h<nw[1].ff)
{
ans=vector<ll> (n,0);
return ans;
}
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;
}
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.out", "w", stdout);
}
ll n, a, b, c;
cin>> n>> a>> b>> c;
vector<ll> vt;
vector<ll> vt1;
for (int i=1;i<=n-1;i++)
{
ll x, y;
cin>>x>> y;
vt.pb(x);
vt1.pb(y);
}
vector<ll> ans=find_split(n,a,b,c, vt,vt1);
}*/
컴파일 시 표준 에러 (stderr) 메시지
split.cpp:18:15: warning: overflow in conversion from 'double' to 'int' changes value from '2.0e+18' to '2147483647' [-Woverflow]
18 | const ll base=2e18;
| ^~~~
split.cpp: In function 'std::vector<int> find_split(int, int, int, int, std::vector<int>, std::vector<int>)':
split.cpp:115: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]
115 | for (int i=1;i<=nw.size();i++) val[nw[i-1].ss]=nw[i-1].ff;
| ~^~~~~~~~~~~
split.cpp:117:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
117 | for (int i=0;i<p.size();i++)
| ~^~~~~~~~~
split.cpp:132:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
132 | for (int i=0;i<adj1[u].size();i++)
| ~^~~~~~~~~~~~~~~
# | 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... |