#define HAVE_STRUCT_TIMESPEC
#include<bits/stdc++.h>
using namespace std;
typedef struct{
int add,data,nex;
}Node;
Node node[],ans[],ans2[];
map<int,int>mp;
int main(){
//ios::sync_with_stdio(false);
//cin.tie(NULL);
//cout.tie(NULL);
int s,n,k;
scanf("%d%d%d",&s,&n,&k);
for(int i=;i<=n;++i){
scanf("%d%d%d",&node[i].add,&node[i].data,&node[i].nex);
mp[node[i].add]=i;
}
int cnt=;
while(s!=-){
int num=mp[s];
ans[++cnt].add=node[num].add;
ans[cnt].data=node[num].data;
ans[cnt].nex=node[num].nex;
s=ans[cnt].nex;
}
int cnt2=;
int x=cnt/k;
if(cnt%k)
++x;
for(int i=x;i;--i){
for(int j=(i-)*k+;j<=min(cnt,i*k);++j){
ans2[++cnt2].add=ans[j].add;
ans2[cnt2].data=ans[j].data;
ans2[cnt2].nex=ans[j].nex;
}
if(i==)
ans2[cnt2].nex=-;
else
ans2[cnt2].nex=ans[(i-)*k+].add;
}
for(int i=;i<=cnt2;++i){
if(i<cnt2)
printf("%05d %d %05d\n",ans2[i].add,ans2[i].data,ans2[i].nex);
else
printf("%05d %d -1",ans2[i].add,ans2[i].data);
}
return ;
}

2019冬季PAT甲级第二题的更多相关文章

  1. 2019冬季PAT甲级第一题

    #define HAVE_STRUCT_TIMESPEC #include<bits/stdc++.h> using namespace std; ][]; ][]; ]; string ...

  2. 2019冬季PAT甲级第四题

    #define HAVE_STRUCT_TIMESPEC #include<bits/stdc++.h> using namespace std; typedef struct node{ ...

  3. 2019冬季PAT甲级第三题

    #define HAVE_STRUCT_TIMESPEC #include<bits/stdc++.h> using namespace std; ]; ]; ]; int main(){ ...

  4. 2019秋季PAT甲级_备考总结

    2019 秋季 PAT 甲级 备考总结 在 2019/9/8 的 PAT 甲级考试中拿到了满分,考试题目的C++题解记录在这里,此处对备考过程和考试情况做一个总结.如果我的方法能帮助到碰巧点进来的有缘 ...

  5. 2019秋季PAT甲级_C++题解

    2019 秋季 PAT (Advanced Level) C++题解 考试拿到了满分但受考场状态和知识水平所限可能方法不够简洁,此处保留记录,仍需多加学习.备考总结(笔记目录)在这里 7-1 Fore ...

  6. 1080 Graduate Admission——PAT甲级真题

    1080 Graduate Admission--PAT甲级练习题 It is said that in 2013, there were about 100 graduate schools rea ...

  7. PAT 甲级真题题解(1-62)

    准备每天刷两题PAT真题.(一句话题解) 1001 A+B Format  模拟输出,注意格式 #include <cstdio> #include <cstring> #in ...

  8. PAT甲级 链表题_C++题解

    链表处理 PAT (Advanced Level) Practice 链表题 目录 <算法笔记> 重点摘要:静态链表 1032 Sharing (25) 1052 Linked List ...

  9. PAT 甲级真题题解(63-120)

    2019/4/3 1063 Set Similarity n个序列分别先放进集合里去重.在询问的时候,遍历A集合中每个数,判断下该数在B集合中是否存在,统计存在个数(分子),分母就是两个集合大小减去分 ...

随机推荐

  1. 4.Docker 操作容器

    启动容器 所需要的命令主要为 docker run.例如,下面的命令输出一个 “Hello World”,之后终止容器. docker run ubuntu:16.04 /bin/echo 'Hell ...

  2. Java大全-吐血整理

    gqzdev

  3. Python-selenium,使用SenKey模块时所碰到的坑

    一.SenKey模块(模拟鼠标键盘操作) :python3中没有该模块,使用PyUserInput模块代替 二.PyUserInput模块安装前需要安装:pywin32和pyHook模块,pywin3 ...

  4. Python开发坦克大战

    Python不仅能开发网站,爬虫数据分析等,他其实也可以写游戏,接下来就给大家分享下坦克大战的代码: PS:很多人在学习Python的过程中,往往因为遇问题解决不了或者没好的教程从而导致自己放弃,为此 ...

  5. C#中常见的winform控件命名规范 转

    我们知道Button 常常简称为btn,那么Winform中的其它控件呢,这篇文章在C#的winform控件命名规范 的基础上对一些控件的名称的简称进行了整理. 1. 标准控件 NO. 控件类型简写 ...

  6. R data formats

    R data formats: Rdata Rda Rds 1.概念 rds是R语言中利用二进制保存的源文件,加载readr包以后,使用write_rds(x,file='x.rds')保存文件,re ...

  7. WDatePicker使用 出现ReferenceError: disabledDates is not defined

    "ReferenceError: disabledDates is not defined at eval (eval at <anonymous> at HTMLInputEl ...

  8. 题解 【Codefoeces687B】Remainders Game

    题意: 给出c1,c2,...cn,问对于任何一个正整数x,给出x%c1,x%c2,...的值x%k的值是否确定; 思路: 中国剩余定理.详见https://blog.csdn.net/acdream ...

  9. 解决前端js、css缓存问题

    去js标签库查询jquery.i18n.properties.js这个js引用到页面上: 新建一个配置文件:用上面的那个js方法调取配置文件里的版本号给其他的js加上: 示例: <script ...

  10. Paper: ModelarDB

    Problem: how to store and querry massive amounts of high quality sensor data ingested in real-time f ...