| ||||||||||
| Online Judge | Problem Set | Authors | Online Contests | User | ||||||
|---|---|---|---|---|---|---|---|---|---|---|
| Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest | |||||||||
当前Rank 999,终于挤进了前1000,1A留念~#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: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator