// ***************************************************************// zoj 2500 version: 1.0 · date: 06/05/2008// -------------------------------------------------------------// 拓扑求序,变形的弗洛伊德方法// -------------------------------------------------------------// Copyright (C) 2008 - All Rights Reserved// ***************************************************************// // ***************************************************************#include <iostream>#include <string> using namespace std;#define MAXN 100 int mat[100][100];int n,m; void initial(){ for (int i=0;i<n;i++) for (int j=0;j<n;j++) mat[i][j]=0;} int run(){ cin>>n>>m; initial(); for (int i=0;i<m;i++) { int aa,bb; cin>>aa>>bb; aa--,bb--; mat[aa][bb]=1; mat[bb][aa]=-1; } for (int k=0;k<n;k++) { for (int i=0;i<n;i++) { for (int j=0;j<n;j++) { if (mat[i][j]==0 && mat[i][k]==1 && mat[k][j]==1) { mat[i][j]=1; mat[j][i]=-1; } if (mat[i][j]==0 && mat[i][k]==-1 && mat[k][j]==-1) { mat[i][j]=-1; mat[j][i]=1; } } } } int lim=(n-1)/2; int ans=0; for (int i=0;i<n;i++) { int larger=0; int smaller=0; for (int j=0;j<n;j++) { if (mat[i][j]==1) larger++; if (mat[i][j]==-1) smaller++; } if (larger>lim) ans++; if (smaller>lim) ans++; } return ans;} int main(){ int re; cin>>re; while (re--) cout<<run()<<endl; return 0;}
zoj 2500
最新推荐文章于 2022-02-25 21:57:21 发布