AcWing 1626. 啥啊,就是烦呐
原题链接
简单
#include<iostream>
#include<algorithm>
using namespace std;
const int N=1e5+9;
int start,n,k;
int v[N],nex[N];
int main()
{
cin>>start>>n>>k;
for(int i=0;i<n;i++)
{
int a,b,c;
cin>>a>>b>>c;
if(c==-1) c=100006;
v[a]=b,nex[a]=c;
}
vector<pair<int,int>> resl,resr;
int t=0;
while(start!=100006)
{
if(v[start]<0)
resl.push_back({v[start],start});
else
resr.push_back({v[start],start});
start=nex[start];
}
resl.insert(resl.end(),resr.begin(),resr.end());
vector<pair<int,int>> res1,res2;
for(int i=0;i<resl.size();i++)
{
if(resl[i].first<=k)
res1.push_back(resl[i]);
else
res2.push_back(resl[i]);
}
res1.insert(res1.end(),res2.begin(),res2.end());
for(int i=0;i<res1.size();i++){
if(i==res1.size()-1)
printf("%05d %d -1\n",res1[i].second,res1[i].first);
else
printf("%05d %d %05d\n",res1[i].second,res1[i].first,res1[i+1].second);
}
return 0;
}