学习:
v1.insert(v1.end(),v2.begin(),v2.end());
v1.insert(v1.end(),v3.begin(),v3.end());
#include<iostream>
#include<vector>
using namespace std;
const int N=1e5+10;
int e[N],ne[N];
int h,n,k;
int main(){
cin>>h>>n>>k;
for(int i=0;i<n;i++){
int address,data,next;
cin>>address>>data>>next;
e[address]=data;
ne[address]=next;
}
vector<int> v1,v2,v3;
for(int i=h;i!=-1;i=ne[i]){
if(e[i]<0) v1.push_back(i);
else if(e[i]>k) v3.push_back(i);
else v2.push_back(i);
}
v1.insert(v1.end(),v2.begin(),v2.end());
v1.insert(v1.end(),v3.begin(),v3.end());
for(int i=0;i<v1.size();i++){
if(i==v1.size()-1) printf("%05d %d -1\n",v1[i],e[v1[i]]);
else printf("%05d %d %05d\n",v1[i],e[v1[i]],v1[i+1]);
}
return 0;
}