杭电oj1567

When the old year is leaving and the New Year is coming, people are always looking back over the past while looking forward to the future.

"What do you think is the most important events in the past year 2006?", a friend asked me.

"Well, maybe the World Cup.", I replied.

"Yeah, do you know, in a football match, how to arrange a proper match table for a group?"

"That's easy. In the World Cup, there are only 4 teams in a group. Everyone knows how to do it."

"Yes, it's easy for four-team’s arrangement. But if there are six teams or more games, can you arrange that?"

"OK, let me have a try". I answered.

In fact, I tried many times to solve the problem, but got failure in the end. Can you help me?

 

 

Input

The input contains data for several test cases.

Each case contains a single even integer, which is less than 2007, indicate the number of teams in a group.
and n-1 lines followed, indicate the match table.each line indicate one round in the contest.For example,
4
1-2 3-4 // the first round
1-3 2-4 // the second round
1-4 2-3 // the third round

 

 

Output

For each test case output "Yes" means the match table is correct, or "No" otherwise.

 

 

Sample Input

 

2

1-2

4

1-2 3-4

1-3 2-4

1-4 2-3

4

1-3 2-4

1-2 3-4

1-4 2-3

4

1-2 3-2

1-3 2-4

1-4 2-3

 

 

Sample Output

 

Yes

Yes

Yes

No

 

 

 

 

#include<iostream>
#include<cstring>
#include <cstdio>
using namespace std;
bool vis[2020];

int main()
{
    //freopen("C:\\Users\\23535\\Desktop\\in.txt","r",stdin); //输入重定向,输入数据将从D盘根目录下的in.txt文件中读取 
//    freopen("C:\\Users\\23535\\Desktop\\out.txt","w",stdout); //输出重定向,输出数据将保存在D盘根目录下的out.txt文件中 
    int n;
    int a,b;
    while(cin>>n)
    {
        int dui[20020]={0};
        int flag=1;
        for(int i=1;i<=n-1;i++)
        {
            memset(vis,0,sizeof(vis));
            for(int j=1;j<=n/2;j++ )
            {
                scanf("%d-%d",&a,&b);
                 if(vis[a]||vis[a]){
                                flag=0;
                            }
                            vis[a]=1;
                            vis[b]=1;
                            dui[a]++;
                            dui[b]++;
            }
        }
        
    
        if(flag){
        
        for(int i=1;i<=n;i++)
        {
            if(dui[i]!=n-1)
            {
                flag=0;
                break;
            }
        }
    }
        //cout<<flag;
        if(flag==1)
            cout<<"Yes"<<endl;
        else
            cout<<"No"<<endl;
            
            
    /*    for(int i=0;i<10;i++)
        {
            cout<<dui[i];
        }
        */
    }
    //fclose(stdin);//关闭重定向输入 
    //fclose(stdout);//关闭重定向输出 
    return 0;
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值