Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

我就不明白哪里搞错了

Posted by qhq00 at 2020-02-13 17:19:31 on Problem 1300
#define first f
#define second s
#define ll long long
#define mp make_pair
#define pb push_back
#define pf push_front
#define lb lower_bound
#define ub upper_bound
//#include<bits/stdc++.h>
#include<stdio.h>
#include<string.h>
#include<iostream>
#define pii pair<int,int>
#define mem(a,b) memset(a,b,sizeof(a))
using namespace std;
const int maxn=1005;

int indx[maxn];
int f[maxn];
char s[maxn],str[maxn];

int getfind(int x)
{
    return x==f[x]?x:getfind(f[x]);
}

int main()
{
    int n,m,k1,k2;
    while(~scanf("%s",&s)){
        if(s[0]=='E'){break;}
        scanf("%d%d",&m,&n);
        getchar();
        for(int i=0;i<n;i++){
            f[i]=i;indx[i]=0;
        }
        int sum=0;
        for(int i=0,len,j,num;i<n;i++){
            gets(str);
            len=strlen(str);
            if(len==0){continue;}
            num=0;
            for(j=0;j<=len;j++){
                if(str[j]==' '||str[j]=='\0'){
                    sum++;
                    indx[num]++;indx[i]++;
                    k1=getfind(i);k2=getfind(num);
                    if(k1!=k2){f[k2]=k1;}
                    num=0;
                }
                else{
                    num=num*10+str[j]-'0';
                }
            }
        }
        gets(str);
        int num=0,ans1=0;
        for(int i=0;i<n;i++){
            if(f[i]==i){num++;}
        }
        if(num>1){printf("NO\n");continue;}
        for(int i=0;i<n;i++){
            if(indx[i]&1){
                ans1++;
            }
        }
        if(ans1==0&&m==0){
            printf("YES %d\n",sum);
        }
        else if(ans1==2&&(indx[0]%2==1)&&(indx[m]%2==1)&&m!=0){
            printf("YES %d\n",sum);
        }
        else{
            printf("NO\n");
        }
    }
    return 0;
}

Followed by:

Post your reply here:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator