#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <algorithm>
#include <cmath>
#include <string>
#include <cstring>
#include <vector>
#include <queue>
#include <map>
#include <set>
#include <stack>
using namespace std;
struct node
{
int data;
int add;
int next;
node()
{
add=-1;
next=-1;
}
};
node cube[100005];
int book[100005]={0};
int main()
{
// freopen("in.txt","r",stdin);
int head,N;
scanf("%d %d",&head,&N);
for(int i=0;i<N;i++)
{
int t1,tdata,t2;
scanf("%d %d %d",&t1,&tdata,&t2);
cube[t1].add=t1;
cube[t1].data=tdata;
cube[t1].next=t2;
}
vector<node> v;
int p=head;
while(p!=-1&&cube[p].add!=-1)
{
v.push_back(cube[p]);
p=cube[p].next;
}
vector<node> v1;
vector<node> v2;
for(vector<node>::iterator it=v.begin();it!=v.end();it++)
{
int id=abs((*it).data);
if(book[id]!=0)
{
v2.push_back(*it);
}
else
{
v1.push_back(*it);
book[id]++;
}
}
for(int i=0;i<v1.size();i++)
{
if(i!=v1.size()-1)
printf("%05d %d %05d\n",v1[i].add,v1[i].data,v1[i+1].add);
else
printf("%05d %d -1\n",v1[i].add,v1[i].data);
}
for(int i=0;i<v2.size();i++)
{
if(i!=v2.size()-1)
printf("%05d %d %05d\n",v2[i].add,v2[i].data,v2[i+1].add);
else
printf("%05d %d -1\n",v2[i].add,v2[i].data);
}
return 0;
}
1097. Deduplication on a Linked List (25)-- v.erase(it)会很慢
最新推荐文章于 2023-10-08 18:19:39 发布