Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <cassert>
- #include <cstdio>
- #include <cstdlib>
- #include <vector>
- #include <string>
- #include <set>
- #include <map>
- #include <algorithm>
- #include <fstream>
- #include <queue>
- #include <memory.h>
- #include <stack>
- #include <deque>
- #define mp make_pair
- #define pb push_back
- #define taskname "A"
- #ifdef LOCAL
- #define LLD "%I64d"
- #else
- #define LLD "%lld"
- #endif
- using namespace std;
- typedef long long int64;
- typedef long double ld;
- int counter,n,m,vertex;
- void root(int a,int b){
- printf("0 %d %d\n",a+1,b+1);
- ++counter;
- if (counter==m)
- exit(0);
- }
- void uni(int a,int b){
- printf("1 %d %d\n",a+1,b+1);
- ++counter;
- if (counter==m)
- exit(0);
- }
- struct tree{
- tree *T1,*T2;
- int root;
- tree(){
- root=-1;
- T1=T2=0;
- }
- tree(tree* t1,tree* t2){
- assert(t1 && t2);
- T1=t1;
- T2=t2;
- root=t1->root;
- }
- };
- tree* getnew(){
- tree* tmp=new tree;
- tmp->root=vertex++;
- return tmp;
- }
- int deep(tree* tr){
- if (tr->T2)
- return deep(tr->T2);
- return tr->root;
- }
- int root(tree* tr){
- if (tr->T1)
- return root(tr->T1);
- return tr->root;
- }
- tree* dop(tree* tr,tree* ne){
- if (tr->T1){
- swap(tr->T1,tr->T2);
- tr->T1=dop(tr->T1,ne);
- return tr;
- }
- tree* tmp=new tree();
- tmp->T1=ne;
- tmp->T2=tr;
- return tmp;
- }
- void iterate(tree* &tr){
- tree* tmp=getnew();
- uni(tmp->root,root(tr));
- int dp=deep(tr);
- root(dp,dp);
- tr=dop(tr,tmp);
- }
- void print(tree* tr){
- if (!tr->T1){
- cerr<<tr->root<<endl;
- return;
- }
- cerr<<root(tr)<<" "<<root(tr->T1)<<" "<<root(tr->T2)<<endl;
- print(tr->T1);
- print(tr->T2);
- }
- int main(){
- #ifdef LOCAL
- freopen(taskname".in","r",stdin);
- freopen(taskname".out","w",stdout);
- #endif
- scanf("%d %d",&n,&m);
- tree* tmp=getnew();
- for (;;){
- iterate(tmp);
- // print(tmp);
- // cerr<<endl;
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement