我没想到 暴力 可以过 真是一个水啊
http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=5013
#include<iostream> #include<stdio.h> #include<cstring> #include<algorithm> using namespace std; int vis[110][110]; int main( ) { int T,N,M,K,u,v; scanf("%d",&T); while( T-- ) { scanf("%d%d%d",&N,&M,&K); memset( vis,false,sizeof(vis) ); for( int i = 1; i <= M; i++ ) { scanf("%d%d",&u,&v); vis[u][v] = true; vis[v][u] = true; } int res = 0; bool fell = true; while( fell ) { fell = false; for( int i = 0; i < N; i++ ) for( int j = i + 1;j < N; j++ ) { if( vis[i][j] )continue; int ans = 0; for( int k = 0; k < N; k++ ) if( vis[i][k] && vis[j][k] )ans++; if( ans >= K ) { vis[i][j] = true; vis[j][i] = true; res++; fell = true; } } } printf("%d\n",res); } }