0% found this document useful (0 votes)
21 views3 pages

Capghep

Uploaded by

Thang Giang
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
21 views3 pages

Capghep

Uploaded by

Thang Giang
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 3

#include <bits/stdc++.

h>
#define MASK(k) (1LL << (k))
#define BIT(x, i) (((x) >> (i)) & 1)
#define __builtin_popcount __builtin_popcountll
#define __builtin_ctz __builtin_ctzll
#define For(i, a, b) for(int i = (int)(a); i <= (int)(b); ++i)
#define Fod(i, a, b) for(int i = (int)(a); i >= (int)(b); --i)
//#define int long long
#define ll long long
#define fastio ios_base::sync_with_stdio(false); cin.tie(NULL);
#define whole(a) a.begin(), a.end()
#define vi vector<int>
#define pii pair<int, int>
#define pb push_back
#define fi first
#define se second
#define mirai ""
template<class X, class Y>
bool minimize(X& x, const Y& y) {
X eps = 1e-9;
if (x > y + eps) {
x = y;
return true;
}
else return false;
}
template<class X, class Y>
bool maximize(X& x, const Y& y) {
X eps = 1e-9;
if (x + eps < y) {
x = y;
return true;
}
else return false;
}
template<class T>
T Abs(const T& x) {
return (x < 0 ? -x : x);
}
const int INF = 1e9 + 7;
const ll oo = 1e18 + 7;
const int MAX = 1000005;
const int MOD = 1e9 + 7;
using namespace std;
int n;
int A[1010][1010];
vector <int> dinhke[100010];
bool visited[1111];
int righ[100010];
void out()
{
cout << -1;
exit(0);
}
struct node
{
int type, x, y;
};
vector<node> res;
bool match(int u)
{
if (visited[u]) return false;
visited[u] = true;

for (int v : dinhke[u])


{
if (righ[v] == 0 || match(righ[v]))
{
righ[v] = u;
return true;
}
}
return false;
}
struct FenWickTree {
int bit[MAX];

void reset () {
memset (bit, 0, sizeof bit);
}

void update (int x, int val) {


for (; x < MAX; x += (x & -x)) bit[x] += val;
}

int get (int x) {


int ans = 0;
for (; x > 0; x -= (x & -x)) ans += bit[x];
return ans;
}
} bit;
int id[100010];
void process(){
cin >> n;
for (int i = 1; i <= n; i++)
{
for (int j = 1; j <= n; j++)
{
cin >> A[i][j];
if (A[i][j] == 1)
{
dinhke[j].push_back(i);
}
}
}
int cnt = 0;
for (int i=1; i<=n; i++)
{
id[i] = i;
memset(visited,0,sizeof(visited));
if(match(i)) cnt++;
}
if (cnt < n) out();

for (int i=1; i<=n; i++)


{
for (int j=i+1; j<=n; j++)
{
if (righ[i] > righ[j])
{
swap(righ[i],righ[j]);
res.push_back({1,i,j});
}
}
}

cout << res.size() << '\n';


for (node &tmp : res) cout << tmp.type << ' ' << tmp.x << ' ' << tmp.y << '\n';
}
signed main()
{
fastio
if (fopen(mirai".inp", "r")) {
freopen(mirai".inp", "r", stdin);
freopen(mirai".out", "w", stdout);
}
int Test = 1;
while (Test--) {
process();
}
return 0;
}

You might also like