QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#368782 | #7791. 通道建设 Passage Construction | NATURAL6 | 0 | 1ms | 6040kb | C++17 | 4.1kb | 2024-03-27 16:22:47 | 2024-03-27 16:22:50 |
answer
#include <bits/stdc++.h>
#include "passageconstruction.h"
using namespace std;
int n,dep[10010],mdep,dfn[10010],tot,fa[14][10010],siz[20010];
int node_siz,edge_siz,id[10010],nowdep,vis[20010],msiz,eid,eU,eV;
vector<int>S[10010],e[10010],E[10010];
vector< pair<int,int> >ans,se[20010];
inline void adde(int x,int y)
{
e[x].emplace_back(y);
fa[0][y]=x;
for(int i=1;i<14;++i)fa[i][y]=fa[i-1][fa[i-1][y]];
return ;
}
inline int get_lca(int x,int y)
{
if(x==y)return x;
if(dep[x]<dep[y])swap(x,y);
for(int i=13;~i;--i)while(dep[fa[i][x]]>=dep[y])x=fa[i][x];
if(x==y)return x;
for(int i=13;~i;--i)while(fa[i][x]^fa[i][y])x=fa[i][x],y=fa[i][y];
return fa[0][x];
}
inline void dfs(int rt)//求 dfs 序
{
dfn[rt]=++tot;
for(int i:e[rt])dfs(i);
return ;
}
inline bool cmp(int x,int y){return dfn[x]<dfn[y];}
inline int build(vector<int>S)
{
sort(S.begin(),S.end(),cmp);
for(int i=(int)S.size()-1;i;--i)S.emplace_back(get_lca(S[i],S[i-1]));
sort(S.begin(),S.end(),cmp);S.resize(unique(S.begin(),S.end())-S.begin());
for(int i=1;i<(int)S.size();++i)E[get_lca(S[i],S[i-1])].emplace_back(S[i]);
return S[0];
}
inline int dfss(int rt,int da)// 三度化
{
if(E[rt].empty())return id[++node_siz]=rt,node_siz;
if(E[rt].size()==1)
{
int U=++node_siz,V=dfss(E[rt][0],rt);
id[U]=rt;++edge_siz;
se[U].emplace_back(make_pair(V,edge_siz));
se[V].emplace_back(make_pair(U,edge_siz));
return U;
}
else
{
int V=dfss(E[rt].back(),rt);
for(int i=E[rt].size()-2;~i;--i)
{
int rot=++node_siz,U=dfss(E[rt][i],rt);
++edge_siz;
se[rot].emplace_back(make_pair(U,edge_siz));
se[U].emplace_back(make_pair(rot,edge_siz));
++edge_siz;
se[rot].emplace_back(make_pair(V,edge_siz));
se[V].emplace_back(make_pair(rot,edge_siz));
U=rot;id[rot]=rt;
}
return V;
}
return 0;
}
inline int get_id(int rt,int da)
{
if(dep[id[rt]]==nowdep)return id[rt];
for(pair<int,int>i:se[rt])
{
if(i.first==da||vis[i.second])continue;
return get_id(i.first,rt);
}
return 0;
}
inline void findroot(int rt,int da,int SZ)
{
if(dep[id[rt]]==nowdep)siz[rt]=1;
else siz[rt]=0;
for(pair<int,int>i:se[rt])
{
if(i.first==da||vis[i.second])continue;
findroot(i.first,rt,SZ);siz[rt]+=i.first;
if(msiz>max(siz[i.first],SZ-siz[i.first]))msiz=max(siz[i.first],SZ-siz[i.first]),eU=rt,eV=i.first,eid=i.second;
}
return ;
}
inline int dfssss(int rt,int da)// 求 siz
{
int an=(dep[id[rt]]==nowdep);
for(pair<int,int>i:se[rt])
{
if(i.first==da||vis[i.second])continue;
an+=dfssss(i.first,rt);
}
return an;
}
inline void dfz(int rt,int SZ,vector<int>nodeset)
{
if(!SZ||nodeset.empty())return ;
if(SZ==1)
{
int ID=get_id(rt,0);
for(int i:nodeset)adde(ID,i);
return ;
}
msiz=SZ+1;
findroot(rt,0,SZ);
vis[eid]=1;
int sizU=dfssss(eU,eV),sizV=dfssss(eV,eU);
vector<int>res,B,toU,toV;B.emplace_back(id[eU]);
for(pair<int,int>i:se[eU])
{
if(i.first==eV||vis[i.second])continue;
B.emplace_back(id[i.first]);
}
if(B.size()==1)res.resize(nodeset.size(),1);
else res=QueryLCA(nodeset,B,id[eU]);
for(int i=0;i<(int)nodeset.size();++i)
{
if(res[i])toU.emplace_back(nodeset[i]);
else toV.emplace_back(nodeset[i]);
}
int eeU=eU,eeV=eV;
dfz(eeU,sizU,toU);dfz(eeV,sizV,toV);
return ;
}
inline void solve(int D)
{
if(D>=2)for(int i:S[D-2])E[i].clear();
for(int i=1;i<=node_siz;++i)se[i].clear();
node_siz=edge_siz=0;
int rot=build(S[D-1]);
rot=dfss(rot,0);
nowdep=D-1;
dfz(rot,node_siz,S[D]);
tot=0;dfs(1);
return ;
}
inline int dfsss(int rt)// 求匹配
{
int son=0;
for(int i:e[rt])
{
int p=dfsss(i);
if(p)
{
if(son)
{
ans.emplace_back(make_pair(p,son));
son=0;
}
else son=p;
}
}
if(son)
{
ans.emplace_back(make_pair(rt,son));
son=0;
}
else son=rt;
return son;
}
vector< pair<int,int> >ConstructPassages(int N,const vector< pair<int,int> >&E)
{
n=N;
for(int i=2;i<=(n<<1);++i)
{
S[dep[i]=GetDistance(1,i)].emplace_back(i);
mdep=max(mdep,dep[i]);
}
S[0].emplace_back(1);dfn[1]=tot=1;
for(int i=1;i<=mdep;++i)solve(i);
dfsss(1);
return ans;
}
详细
Subtask #1:
score: 0
Time Limit Exceeded
Test #1:
score: 3
Accepted
time: 1ms
memory: 6040kb
input:
1 1872884041 100 100 10000 10000 1 2294931821 2294931820
output:
Succeeded 0 1 0 0 1 2
result:
ok Accepted with 0+1 operations,sum of size(s)=0+0
Test #2:
score: 0
Time Limit Exceeded
input:
1 1977600624 100 100 10000 10000 5 621522394 621522399 2231003352 2231003338 464307841 464307837 1851407771 1851407768 2780336863 2780336849 314073909 314073902 1173467454 1173467430 4215033871 4215033843 2620057116 2620057098
output:
Unauthorized output
result:
Subtask #2:
score: 0
Time Limit Exceeded
Test #11:
score: 0
Time Limit Exceeded
input:
2 755640766 20000 10000 200000 200000 100 4287951944 4287951892 218593589 218593610 2907028702 2907028595 100123056 100122959 3149201405 3149201229 3454414687 3454414608 1901257489 1901257490 1532337798 1532337686 836222214 836222227 187381584 187381446 1847826999 1847827071 2868544732 2868544653 41...
output:
Unauthorized output
result:
Subtask #3:
score: 0
Time Limit Exceeded
Test #19:
score: 0
Time Limit Exceeded
input:
3 397960972 100000 4000 200000 200000 1000 3136131587 3136131078 3887641427 3887642253 280951546 280951198 124187343 124186744 3948118891 3948118785 2174920490 2174920140 3041102338 3041103477 489656932 489656480 3093689453 3093690199 3027233105 3027233261 967551350 967551424 215138938 215138436 251...
output:
Unauthorized output
result:
Subtask #4:
score: 0
Time Limit Exceeded
Test #29:
score: 0
Time Limit Exceeded
input:
4 1084797752 100000 4000 200000 200000 1000 3456536122 3456534568 249115651 249115791 3576312078 3576312237 1880897416 1880895547 1944688480 1944688327 248846397 248847256 3567405828 3567405196 1084965392 1084965206 1435956247 1435955729 3887033767 3887032464 307260230 307260472 1476733874 147673312...
output:
Unauthorized output
result:
Subtask #5:
score: 0
Time Limit Exceeded
Test #39:
score: 0
Time Limit Exceeded
input:
5 1720909858 50000 4000 200000 100000 998 195378529 195378218 2138942224 2138942028 2421726252 2421725316 2614111628 2614111784 3778296551 3778295886 3346314089 3346313971 701234060 701233448 279201944 279202119 69826850 69826766 2173156660 2173157126 2982274003 2982273048 2306106121 2306107345 2808...
output:
Unauthorized output
result:
Subtask #6:
score: 0
Time Limit Exceeded
Test #50:
score: 0
Time Limit Exceeded
input:
6 889180297 25000 4000 200000 100000 998 3680334935 3680334330 2957217208 2957215867 3096097757 3096097331 2843029536 2843030717 2270437916 2270437982 1841161075 1841160444 3671823118 3671823208 2166904224 2166903071 2760262295 2760263328 880472976 880472564 3147819342 3147820514 3366602035 33666019...
output:
Unauthorized output
result:
Subtask #7:
score: 0
Time Limit Exceeded
Test #59:
score: 0
Time Limit Exceeded
input:
7 1561772597 25000 4000 200000 100000 1000 834919143 834919090 162625904 162627303 1067517190 1067517712 3410644901 3410644677 2728503196 2728502622 4133685425 4133685598 976760503 976760426 2101358026 2101358499 3583017242 3583017016 1743218912 1743220527 2609984627 2609985177 3915259025 3915259188...
output:
Unauthorized output
result:
Subtask #8:
score: 0
Time Limit Exceeded
Test #70:
score: 0
Time Limit Exceeded
input:
8 1311447458 50000 100000 500000 200000 4999 173190562 173182163 1078196947 1078197142 1215565665 1215571165 1186082670 1186081354 2422459084 2422459806 2626070241 2626074599 207492448 207494582 2266700305 2266695214 1679673055 1679672568 3879988278 3879982030 254940475 254941572 3919251618 39192495...
output:
Unauthorized output
result:
Subtask #9:
score: 0
Time Limit Exceeded
Test #81:
score: 0
Time Limit Exceeded
input:
9 574951428 15000 10000 200000 50000 5000 1781472251 1781466624 803445324 803444785 3544280892 3544283003 3151400420 3151403948 3250864128 3250871501 4189507543 4189510374 3483519516 3483520446 1003612935 1003617460 1101934749 1101931586 1948046579 1948042301 4151407804 4151401951 424123439 42412196...
output:
Unauthorized output