48 lines
1.4 KiB
C++
48 lines
1.4 KiB
C++
#include <cstdio>
|
||
#include <iostream>
|
||
#include <string>
|
||
#include <sstream>
|
||
#include <cstring>
|
||
using namespace std;
|
||
|
||
const int N = 20;
|
||
int m, n, d[N];
|
||
|
||
int main() {
|
||
string s;
|
||
while (getline(cin, s), s != "ENDOFINPUT") {
|
||
memset(d, 0, sizeof d); // 多组测试数据,清空度数组
|
||
|
||
istringstream sin;
|
||
sin.str(s); // 用s输入进行构建
|
||
sin >> s >> m >> n; // 进1出3
|
||
|
||
int cnt = 0;
|
||
for (int i = 0; i < n; i++) {
|
||
getline(cin, s); // 读取整行
|
||
if (!s.size()) continue; // 如果本行输入是空的,那么处理下一行
|
||
sin.clear(); // istringstream这东西如果想重复使用,需要先清空
|
||
sin.str(s); // 用s输入进行构建
|
||
int j;
|
||
while (sin >> j) { // 循环输出j
|
||
d[i]++, d[j]++;
|
||
++cnt;
|
||
}
|
||
}
|
||
// 读入END
|
||
getline(cin, s);
|
||
|
||
// 检查欧拉回路和欧拉路径
|
||
int odd = 0;
|
||
for (int i = 0; i < n; i++)
|
||
if (d[i] % 2) odd++;
|
||
|
||
if (odd == 0 && m == 0)
|
||
cout << "YES " << cnt << endl;
|
||
else if (odd == 2 && m != 0 && d[0] % 2 == 1 && d[m] % 2 == 1)
|
||
cout << "YES " << cnt << endl;
|
||
else
|
||
cout << "NO" << endl;
|
||
}
|
||
return 0;
|
||
} |