题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3357
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <iostream>
#include <cstring>
#include <queue>
#include <vector> #define maxn 250
#define maxe 100050
#define INF 0x3f3f3f
using namespace std; int N,T;
int ans;
bool G[maxn][maxn];
int l[maxn];
int r[maxn];
int lhead,ltail,rhead,rtail;
int main()
{
//freopen("input.txt","r",stdin);
int t=;
while(scanf("%d%d",&N,&T) && N + T){
memset(G,,sizeof(G));
ans = ;
for(int i=;i<=T;i++){
int u,v;
scanf("%d%d",&u,&v);
if(G[v][u] || u == v){
ans++;
continue;
}
G[u][v] = ;
lhead = ltail = rhead = rtail = ;
for(int i=;i<=N;i++){
if(G[i][u]) {G[i][v] = ; l[ltail++] = i;}
if(G[v][i]) {G[u][i] = ; r[rtail++] = i;}
}
for(int j=lhead;j<ltail;j++)
for(int k=rhead;k<rtail;k++){
G[l[j]][r[k]] = ;
}
}
printf("%d. %d\n",t++,ans);
}
}