社区讨论
今年听过第二好笑的笑话。
P2495【模板】虚树 / [SDOI2011] 消耗战参与者 6已保存回复 12
讨论操作
快速查看讨论及其快照的属性,并进行相关操作。
- 当前回复
- 12 条
- 当前快照
- 1 份
- 快照标识符
- @mi1bhg4n
- 此快照首次捕获于
- 2025/11/16 14:10 3 个月前
- 此快照最后确认于
- 2025/11/17 09:13 3 个月前
代码前半段。
CPP#include<bits/stdc++.h>
#define ll long long
using namespace std;
ll tot,st[250010],depth[250010],top,u,v,w,n,m,minl[250010],k,h[250010],bz[250010][20],dfn[250010],cnt,used[250005];
vector<pair<ll,ll> > edge[250010];
ll xutre[250010];
ll head[250010],nxt[250010];
void add(ll a,ll b){
tot++;
xutre[tot]=b;
nxt[tot]=head[a];
head[a]=tot;
}
void dfs(ll x,ll fa){
dfn[x]=++cnt;
bz[x][0]=fa;
depth[x]=depth[fa]+1;
for(ll i=0;i<edge[x].size();i++){
if(edge[x][i].first==fa)continue;
minl[edge[x][i].first]=min(minl[x],edge[x][i].second);
dfs(edge[x][i].first,x);
}
}
bool cmp(ll a,ll b){
return (dfs[a])<(dfs[b]);
}
ll lca(ll a,ll b){
ll ta=a,tb=b;
if(depth[a]<depth[b])swap(a,b);
for(int i=18;i>=0;i--){
if(depth[bz[a][i]]>=depth[b]){
a=bz[a][i];
}
}
if(a==b){
// cout<<"lca of "<<ta<<' '<<tb<<" is "<<a<<endl;
return a;
}
for(int i=18;i>=0;i--){
if(bz[a][i]!=bz[b][i]){
a=bz[a][i];
b=bz[b][i];
}
}
// cout<<"lca of "<<ta<<' '<<tb<<" is "<<bz[a][0]<<endl;
return bz[a][0];
}
void buildxs(){
ll temp;
sort(h+1,h+1+k,cmp);
// for(int i=1;i<=k;i++){
// cout<<h[i]<<' ';
// }
top=1;
st[top]=1;
if(h[1]!=1){
st[++top]=h[1];
}
for(int i=2;i<=k;i++){
temp=lca(h[i],st[top]);
if(st[top]==temp){
st[++top]=h[i];
}else{
while(depth[st[top-1]]>depth[temp]){
add(st[top-1],st[top]);
// cout<<"ADD:"<<st[top-1]<<' '<<st[top]<<'\n';
top--;
}
if(temp==st[top-1]){
// st[++top]=h[i];
add(temp,st[top]);
// cout<<"ADD:"<<temp<<' '<<st[top]<<'\n';
top--;
// st[++top]=temp;
st[++top]=h[i];
}else{
add(temp,st[top]);
// cout<<"ADD:"<<temp<<' '<<st[top]<<'\n';
top--;
st[++top]=temp;
st[++top]=h[i];
}
}
}
while(top>1){
add(st[top-1],st[top]);
// cout<<"ADD:"<<st[top-1]<<' '<<st[top]<<'\n';
top--;
}
// cout<<tot<<endl;
}
卡了 1.5h ,亮点自寻。
这是怎么能有30的
回复
共 12 条回复,欢迎继续交流。
正在加载回复...