这题目的数据范围是否有问题。
题目保证没有重边和自环。点个数n(1≤n≤1000)
那么边开2*n 是否就可以了?
我的代码 边要开启点个数200倍才能ac。
还是我代码问题??
// 22222.cpp : 此文件包含 "main" 函数。程序执行将在此处开始并结束。
//
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <cstring>
using namespace std;
/*
https://www.papamelon.com/problem/242
*/
const int N = 10010;
const int M = 2000010;
int h[N], e[M], ne[M];
int idx;
int n, m;
int point[N];
void add(int a, int b) {
e[idx] = b, ne[idx] = h[a]; h[a]=idx++;
}
bool dfs(int x, int color) {
if (point[x] != 0 && point[x] != color) return false;
else if (point[x] != 0) return true;
else if (point[x] == 0) { point[x] = color; }
for (int i = h[x]; i != -1; i = ne[i]) {
int j = e[i];
if (false == dfs(j, (color+2)%2+1)) {
return false;
}
}
return true;
}
int main()
{
cin >> n ;
memset(h,-1,sizeof h);
memset(point, 0, sizeof point);
int a, b;
while (scanf("%d%d", &a, &b) != EOF) {
add(a, b); add(b, a);
}
for (int i = 0; i < n; i++) {
if (point[i] == 0) {
if (dfs(i, 1) == false) {
cout << "No" << endl; return 0;
}
}
}
cout << "Yes" << endl;
return 0;
}
const int N = 10010;
const int M = 20010;
就会runtime error