A 牛妹的游戏

链接:https://ac.nowcoder.com/acm/contest/5205/A

思路:

 1 #include <bits/stdc++.h>
 2 using namespace std;
 3 const int maxn=107;
 4 int g[maxn][maxn];
 5 int main(){
 6     int t,n,m,x,y;
 7     scanf("%d",&t);
 8     while(t--){
 9         memset(g,0,sizeof(g));
10         scanf("%d%d",&n,&m);
11          
12         if(n>5) {
13             for(int i=0;i<m;i++){
14                 scanf("%d%d",&x,&y);
15             }
16             puts("yes");
17              
18         }
19         else{
20             for(int i=0;i<m;i++){
21                 scanf("%d%d",&x,&y);
22                 g[x][y]=1;
23                 g[y][x]=1;
24             }
25             int flag=0;
26             for(int k=1;k<=n;k++){
27                 for(int i=k+1;i<=n;i++){
28                     for(int j=i+1;j<=n;j++){
29                         int f=g[k][i]+g[i][j]+g[j][k];
30                         if(f==0 || f==3){
31                             flag=1;
32                         }
33                     }
34                 }
35             }
36             if(flag) puts("yes");
37             else puts("no");
38         }
39     }
40     return 0;
41 }
View Code

猜你喜欢

转载自www.cnblogs.com/pangbi/p/12902030.html