#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. linux用户管理相关命令

    查看用户以及用户组: cat /etc/group   [root@izuf60kjjii4iwkhdsly3bz html]# cat /etc/group   内容具体分析 /etc/group ...

  2. [CF527D] Clique Problem - 贪心

    数轴上有n 个点,第i 个点的坐标为xi,权值为wi.两个点i,j之间存在一条边当且仅当 abs(xi-xj)>=wi+wj. 你需要求出这张图的最大团的点数. Solution 把每个点看作以 ...

  3. netcore 添加swagger

    1.添加相应的nuget包  2.配置服务和swaggerui startup.cs 中 configureServices 中添加下面代码: //swagger services.AddSwagge ...

  4. linux - mysql 异常:Ignoring query to other database

    问题描述 Ignoring query to other database(忽略其他数据库查询) 问题原因 登录方式错误,登录命令用的是 “mysql -root -p”,应该用命令 “mysql - ...

  5. 让Surface Shader不受光照的明暗影响

    直接上码 Shader "Custom/3DVideo" { Properties { _Color (,,,) _MainTex ("Albedo (RGB)" ...

  6. QT版本

    最近在linux下安装qt:发现主要的问题是qt的版本问题:下面来谈谈各个版本的理解 Qt 的版本是按照不同的图形系统来划分的,目前分为五个版本: Win: 适用于Miccrosoft Windows ...

  7. EntityFramework之原始查询及性能优化

    之前做海信项目,数据量自交大,为了提高查询效率用的 https://www.cnblogs.com/CreateMyself/p/4746258.html

  8. Gin_入门

    1. 创建路由 1.1 Restful风格的API gin支持Restful风格的API 即Representational State Transfer的缩写.直接翻译的意思是"表现层状态 ...

  9. EF中的实体关系

    导航属性的理解: 指数据库的表所对应的实体类,除了要有每个字段所对应的属性之外,还应该有一个与之有关联的表的属性,一对一的关系就是关联表的类型,一对多的关系就是关联表的类型的ICollection的泛 ...

  10. [HAOI2016] 找相同字符 - 后缀数组,单调栈

    [HAOI2016] 找相同字符 Description 给定两个字符串,求出在两个字符串中各取出一个子串使得这两个子串相同的方案数.两个方案不同当且仅当这两个子串中有一个位置不同. \(n,m \l ...