给出ac代码:
#include <stdio.h>
#include <string.h>
#include <algorithm>
using namespace std;
const int maxn=110,maxm=1e4+7;
int g[maxn][maxn];
int col[maxn],row[maxn];
int h[maxn],e[maxm],ne[maxm],idx;
int match[maxn];
bool vis[maxn];
int n,m;
struct ops{
int a,b;
}op[maxn];
void add(int a,int b){
e[idx]=b,ne[idx]=h[a],h[a]=idx++;
}
int find(int x){
for(int i=h[x];~i;i=ne[i]){
int j=e[i];
if(vis[j])continue;vis[j]=1;
if(match[j]==-1||find(match[j])){
match[j]=x;
return 1;
}
}
return 0;
}
int main()
{
while(~scanf("%d",&n)){
memset(h,-1,sizeof h),idx=0;int flag=1;
memset(col,0,sizeof col);memset(row,0,sizeof row);memset(match,-1,sizeof match);
for(int i=1;i<=n;i++)for(int j=1;j<=n;j++){
scanf("%d",&g[i][j]);
if(g[i][j])add(i,j),row[i]++,col[j]++;
}
for(int i=1;i<=n;i++){
memset(vis,0,sizeof vis);
int f=find(i);
if(!f){flag=0;break;}
}
if(!flag)puts("-1");
else{
for(int i=1;i<=n;i++)row[i]=i,col[i]=i;
int res=0;
for(int i=1;i<=n;i++){
int a=col[i],b=match[i];
if(row[a]!=row[b])op[++res]={row[a],row[b]},swap(row[a],row[b]),col[row[a]]=a,col[row[b]]=b;
}
printf("%d\n",res);
for(int i=1;i<=res;i++)printf("R %d %d\n",op[i].a,op[i].b);
}
}
return 0;
}