Link
#include "iostream"
using namespace std ;
struct Node
{
Node *to,*from ;
int number,value ;
} ;
int n,k ;
Node book[100005] ;
void init()
{
book[0].to=&book[1] ;
for(int i=1;i<=n;++i)
{
book[i].to=&book[i+1] ;
book[i].from=&book[i-1] ;
book[i].number=book[i].value=i ;
}
}
Node * find(int number)
{
Node *u=&book[0] ;
for(int i=1;i<=number;++i) u=u->to ;
return u ;
}
void change(Node *start,Node *end,Node *to)
{
start->from->to=end->to ;
end->to->from=start->from ;
end->to=to->to ;
to->to->from=end ;
to->to=start ;
start->from=to ;
}
int main()
{
cin>>n>>k ;
init() ;
for(int i=1,a,b,c;i<=k;++i)
{
cin>>a>>b>>c ;
change(find(a),find(b),find(c)) ;
}
int i=1 ;
for(Node *u=book[0].to;i<=10;u=u->to,++i)
{
cout<<u->number<<endl ;
}
return 0 ;
}