[第1章 1.1t1] 队列安排

123 字
1 分钟
[第1章 1.1t1] 队列安排
//使用结构体数组模拟链表,节省查找时间,实在是高
//注意初始化中需要一个虚拟0位置作为全链条最左侧或最右侧
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll MAXN=1e5+5;
struct node{
ll l,r;
ll d;
}m[MAXN];
void solve(){
ll n;
cin>>n;
m[1].d=1;
m[1].l=0,m[1].r=0;
m[0].d=0;
m[0].l=0,m[0].r=1;
for(ll i=2;i<=n;i++){
ll k,p;
cin>>k>>p;
if(p==0){
m[i].r=k;
m[i].l=m[k].l;
m[m[k].l].r=i;
m[k].l=i;
}else{
m[i].l=k;
m[i].r=m[k].r;
m[m[k].r].l=i;
m[k].r=i;
}
m[i].d=1;
}
ll nn;
cin>>nn;
for(ll i=0;i<nn;i++){
ll x;
cin>>x;
m[x].d=0;
}
ll now=m[0].r;
while(now!=0){
if(m[now].d){
if(now!=m[0].r)cout<<" ";
cout<<now;
}
now=m[now].r;
}
cout<<endl;
}
int main(){
solve();
return 0;
}

支持与分享

如果这篇文章对你有帮助,欢迎分享给更多人或打赏支持!

打赏
[第1章 1.1t1] 队列安排
https://hecloud.top/posts/oi/11t1-队列安排/
作者
贺小云
发布于
2026-06-26
许可协议
CC BY-NC-SA 4.0

评论区

Profile Image of the Author
贺小云
热爱技术与折腾的博客 Dancing with uncertainty. 与不确定性共舞
公告
出于成本考虑,贺云已全面转型Serverless架构
分类
标签
碎碎念
站点统计
文章
68
分类
6
标签
38
总字数
46,536
运行时长
0
最后活动
0 天前
站点信息
构建平台
GitHub Actions
博客版本
Firefly v6.16.5
文章许可
CC BY-NC-SA 4.0

当前页面没有目录