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

当前Rank 999,终于挤进了前1000,1A留念~

Posted by vjubge4 at 2019-06-18 09:19:43 on Problem 1300
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
int degree[21];
char buf[1024];
int S, N, M;
int main() {
    while(true) {
        scanf("%s", buf);
        if(strcmp(buf, "ENDOFINPUT") == 0) {
            break;
        }
        memset(degree, 0, sizeof(degree));
        M = 0;
        scanf("%d %d", &S, &N);
        getchar();
        for(int i = 0; i < N; i ++) {
            gets(buf);
            int L = strlen(buf);
            int idx = 0;
            while(idx < L) {
                int a = 0;
                sscanf(buf + idx, "%d", &a);
                M ++;
                degree[i] ++;
                degree[a] ++;
                idx ++;
                while (idx < L && buf[idx] != ' ') {
                    idx ++;
                }
            }
        }
        if(S == 0) {
            bool flag = true;
            for(int i = 0; i < N; i ++) {
                if(degree[i] & 1) {
                    flag = false;
                    break;
                }
            }
            if(flag) {
                printf("YES %d\n", M);
            } else {
                printf("NO\n");
            }
        } else {
            int c = 0;
            for(int i = 0; i < N; i ++) {
                if(degree[i] % 2 == 0) {
                    c ++;
                }
            }
            if(c == N - 2 && degree[0] & 1 && degree[S] & 1){
                printf("YES %d\n", M);
            } else {
                printf("NO\n");
            }
        }
        gets(buf);
    }
}

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