QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#88627#5745. Graph Isomorphismgalaxias#WA 14ms5724kbC++141.3kb2023-03-16 19:59:102023-03-16 19:59:13

Judging History

你现在查看的是最新测评结果

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-03-16 19:59:13]
  • 评测
  • 测评结果:WA
  • 用时:14ms
  • 内存:5724kb
  • [2023-03-16 19:59:10]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 10;
vector<int> G[N];

int a[5][5] , n , m , deg[N];

int read()
{
	int x;
	scanf("%d" , &x);
	return x;
}

bool force()
{
	for(int i = 1 ; i <= m ; ++ i)
	{
		int x = read() , y = read();
		a[x][y] = a[y][x] = 1;
	}
	int p[5];
	for(int i = 1 ; i <= n ; ++ i)
		p[i] = i;
	int cnt = 0;
	do
	{
		bool flag = true;
		for(int i = 1 ; i <= n ; ++ i)
			for(int j = 1 ; j <= n ; ++ j)
				if(a[i][j] && (!a[p[i]][p[j]])) flag = false;
		cnt += flag;
	}while(next_permutation(p + 1 , p + 1 + n));
	return cnt > n;
}

bool solve()
{
	scanf("%d%d", &n, &m);
	if(n <= 4) return force();
	for(int i = 1; i <= n; i ++) deg[i] = 0;
	int mx = 0;
	for(int i = 1; i <= m; i ++)
	{
		int u, v;
		scanf("%d%d", &u, &v);
		G[u].push_back(v);
		G[v].push_back(u);
		deg[u] ++;
		deg[v] ++;
		mx = max(mx, deg[u]);
		mx = max(mx, deg[v]);
	}
	if(m == 1ll * n * (n - 1) / 2) return true;
	if(m == 0) return true;
	int cnt1 = 0 , cnt2 = 0;
	for(int i = 1 ; i <= n ; ++ i)
		cnt1 += (deg[i] == 1) , cnt2 += (deg[i] == n - 1);
	if((cnt1 == n - 1) && (cnt2 == 1)) return true;
	if((cnt1 == 1) && (cnt2 == n - 1)) return true;
	return false;
}

int main()
{
	int T;
	scanf("%d", &T);
	while(T --)
		if(solve()) puts("YES");
		else puts("NO");
	return 0;
}

詳細信息

Test #1:

score: 100
Accepted
time: 0ms
memory: 5724kb

input:

3
3 3
1 2
2 3
3 1
3 2
1 2
2 3
5 5
1 2
2 3
3 4
4 5
5 1

output:

YES
YES
NO

result:

ok 3 token(s): yes count is 2, no count is 1

Test #2:

score: -100
Wrong Answer
time: 14ms
memory: 5612kb

input:

39982
3 2
2 1
3 2
2 1
1 2
2 1
2 1
3 3
3 1
2 3
1 2
2 1
1 2
3 3
3 1
3 2
2 1
2 1
1 2
3 2
1 2
3 1
3 3
2 1
3 1
2 3
2 1
1 2
3 2
2 1
3 2
3 3
2 3
3 1
2 1
3 3
2 1
1 3
2 3
3 3
3 1
3 2
1 2
2 1
2 1
2 1
2 1
3 1
3 1
2 1
2 1
2 1
1 2
3 2
1 3
3 2
3 2
1 2
1 3
3 2
3 2
1 3
2 1
1 2
3 2
3 2
3 1
3 3
2 3
3 1
1 2
2 1
1 2
3 ...

output:

NO
NO
NO
YES
NO
YES
NO
YES
YES
NO
YES
YES
YES
YES
NO
NO
YES
NO
NO
YES
YES
YES
NO
YES
YES
NO
YES
NO
YES
NO
NO
NO
YES
NO
YES
NO
YES
YES
NO
NO
NO
NO
YES
YES
YES
YES
NO
NO
NO
NO
YES
NO
NO
NO
YES
NO
YES
YES
NO
YES
NO
YES
YES
YES
YES
NO
NO
NO
YES
NO
YES
NO
YES
YES
YES
NO
NO
NO
YES
YES
YES
YES
NO
YES
NO
YE...

result:

wrong answer expected YES, found NO [1st token]