C. Below the Diagonal

You are given a square matrix consisting of n rows and n columns. We assume that the rows are numbered from 1 to n from top to bottom and the columns are numbered from 1 to n from left to right. Some cells (n - 1 cells in total) of the the matrix are filled with ones, the remaining cells are filled with zeros. We can apply the following operations to the matrix:

  1. Swap i-th and j-th rows of the matrix;
  2. Swap i-th and j-th columns of the matrix.

You are asked to transform the matrix into a special form using these operations. In that special form all the ones must be in the cells that lie below the main diagonal. Cell of the matrix, which is located on the intersection of the i-th row and of the j-th column, lies below the main diagonal if i > j.

Input

The first line contains an integer n (2 ≤ n ≤ 1000) — the number of rows and columns. Then follow n - 1 lines that contain one's positions, one per line. Each position is described by two integers xk, yk (1 ≤ xk, yk ≤ n), separated by a space. A pair (xk, yk) means that the cell, which is located on the intersection of the xk-th row and of the yk-th column, contains one.

It is guaranteed that all positions are distinct.

Output

Print the description of your actions. These actions should transform the matrix to the described special form.

In the first line you should print a non-negative integer m (m ≤ 105) — the number of actions. In each of the next m lines print three space-separated integers t, i, j (1 ≤ t ≤ 2, 1 ≤ i, j ≤ n, i ≠ j), where t = 1 if you want to swap rows, t = 2 if you want to swap columns, and i and jdenote the numbers of rows or columns respectively.

Please note, that you do not need to minimize the number of operations, but their number should not exceed 105. If there are several solutions, you may print any of them.

Examples

input

Copy

2
1 2

output

Copy

2
2 1 2
1 1 2

input

Copy

3
3 1
1 3

output

Copy

3
2 2 3
1 1 3
1 1 2

input

Copy

3
2 1
3 2

output

Copy

0

这个题就让上三角矩阵没有1,想找合适的行的位置,再找合适的列的位置,一步步缩小矩阵的范围,进而求解。


#include<iostream>
#include<queue>
#include<algorithm>
#include<set>
#include<cmath>
#include<vector>
#include<map>
#include<stack>
#include<bitset>
#include<cstdio>
#include<cstring>
//---------------------------------Sexy operation--------------------------//#define cini(n) scanf("%d",&n)
#define cinl(n) scanf("%lld",&n)
#define cinc(n) scanf("%c",&n)
#define cins(s) scanf("%s",s)
#define coui(n) printf("%d",n)
#define couc(n) printf("%c",n)
#define coul(n) printf("%lld",n)
#define debug(n) printf("%d_________________________________\n",n);
#define speed ios_base::sync_with_stdio(0)
#define file  freopen("input.txt","r",stdin);freopen("output.txt","w",stdout)
//-------------------------------Actual option------------------------------//#define Swap(a,b) a^=b^=a^=b
#define Max(a,b) a>b?a:b
#define Min(a,b) a<b?a:b
#define mem(n,x) memset(n,x,sizeof(n))
#define mp(a,b) make_pair(a,b)
#define pb(n)  push_back(n)
//--------------------------------constant----------------------------------//#define INF  0x3f3f3f3f
#define maxn  100005
#define esp  1e-9
using namespace std;
typedef long long ll;
typedef pair<int,int> PII;
//------------------------------Dividing Line--------------------------------//
int main()
{speed;int n,x[maxn],y[maxn],a[maxn],b[maxn],c[maxn],cnt=0;cin>>n;for(int i=1; i<n; ++i) cin>>x[i]>>y[i];for(int i=1; i<n; ++i){if(x[i]!=i+1){for(int j=i+1; j<n; j++)if(x[j]==i+1)x[j]=x[i];else if(x[j]==x[i])x[j]=i+1;a[cnt]=1,b[cnt]=x[i],c[cnt++]=i+1;}if(y[i]>i){for(int j=i+1; j<n; j++)if(y[j]==i) y[j]=y[i];else if(y[j]==y[i])  y[j]=i;a[cnt]=2,b[cnt]=y[i],c[cnt++]=i;}}cout<<cnt<<endl;for(int i=0; i<cnt; ++i) cout<<a[i]<<" "<<b[i]<<" "<<c[i]<<endl;return 0;
}

codeforce 266c Below the Diagonal 矩阵变换 (思维题)相关推荐

  1. ACM思维题训练 Section A

    题目地址: 选题为入门的Codeforce div2/div1的C题和D题. 题解: A:CF思维联系–CodeForces -214C (拓扑排序+思维+贪心) B:CF–思维练习-- CodeFo ...

  2. little w and Soda(思维题)

    链接:https://ac.nowcoder.com/acm/contest/297/A 来源:牛客网 时间限制:C/C++ 1秒,其他语言2秒 空间限制:C/C++ 262144K,其他语言5242 ...

  3. ZOJ 3829 贪心 思维题

    http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=3829 现场做这道题的时候,感觉是思维题.自己智商不够.不敢搞,想着队友智商 ...

  4. yoyo思维题(困难) 组合数学

    问题 B: yoyo思维题(困难) 时间限制: 1 Sec  内存限制: 256 MB 提交: 11  解决: 3 [提交][状态][讨论版][命题人:qianyouyou][Edit] [TestD ...

  5. 1884: 三个家庭(思维题)

    1884: 三个家庭 Time Limit: 1 Sec Memory Limit: 128 MB Submit: 244 Solved: 81 [Submit][Status][Web Board] ...

  6. 思维题 UVA 10881 Piotr's Ants

    题目传送门 1 /* 2 题意:在坐标轴上一群蚂蚁向左或向右爬,问经过ts后,蚂蚁的位置和状态 3 思维题:本题的关键1:蚂蚁相撞看作是对穿过去,那么只要判断谁是谁就可以了 4 关键2:蚂蚁的相对位置 ...

  7. CF--思维练习-- CodeForces - 215C - Crosses(思维题)

    ACM思维题训练集合 There is a board with a grid consisting of n rows and m columns, the rows are numbered fr ...

  8. CodeForces - 1102A(思维题)

    https://vjudge.net/problem/2135388/origin Describe You are given an integer sequence 1,2,-,n. You ha ...

  9. ☆【CodeForces - 764C】Timofey and a tree (思维题,树的性质)

    题干: Each New Year Timofey and his friends cut down a tree of n vertices and bring it home. After tha ...

最新文章

  1. 研究性能测试工具之systemtap入门指南(四)
  2. OPA 3 - thirdParty Qunit.js and IFrame load logic
  3. linux e32,linux PXE无人值守安装出现 PXE-E32:TFTP OPen timeout的解
  4. 裁判打分_内在的裁判偏见
  5. Gaussian LDA(高斯LDA)简介
  6. Linux “百变”秀:今天 Windows 95,明天 Mac OS 9
  7. 2021年安徽庐江中学朱天乐高考成绩查询,庐江中学举行2021届高三大型励志报告会...
  8. Mybatis-学习笔记(9)Mybatis3+spring4+springMVC
  9. 皇帝的新脑-读书笔记
  10. 仿微信导航栏滑动门练习
  11. 程序员常用的这十个电子书下载网站,你值得拥有!
  12. 弹丸论破2 中文攻略
  13. 注册smtp服务器,SMTP授权码介绍及获取教程
  14. 手机端,网站页面被浏览器转码
  15. 大神详细的ACM训练计划
  16. 击穿面试官的套路:经典面试问题剖析
  17. 我们该如何全面提高程序的可读性
  18. 2020第八届“泰迪杯”特等奖(基于 BERT 深度语言模型的“智慧政务”文本挖掘应用)
  19. eclipse各(旧)版本,32位/64位下载官网地址
  20. 案例分享:Qt政务标签设计器,标签排版软件定制与打印

热门文章

  1. 分享一个好用的函数吧,将js中的对象转成url参数
  2. JHipster生成微服务架构的应用栈(一)- 准备工作
  3. android studio 65536错误的解决
  4. Boost中的Timer的使用——计算时间流逝
  5. C# 去除文件或 文件夹只读属性
  6. 【MFC相关】MFC入门相关
  7. vim多窗口使用技巧
  8. 关于通过DDMS向Android系统的模拟器的sdcard中导入mp3文件的问题
  9. 经典C/C++面试题
  10. 微型计算机及接口技术笔记,微机原理与接口技术笔记(一)