QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#88799#5745. Graph IsomorphismgalaxiasWA 230ms6004kbC++142.0kb2023-03-17 14:42:162023-03-17 14:42:17

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-17 14:42:17]
  • 评测
  • 测评结果:WA
  • 用时:230ms
  • 内存:6004kb
  • [2023-03-17 14:42:16]
  • 提交

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] , d[5][5];

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

int b[10] = {1 , 1 , 1 , 2 , 2 , 3} , c[10] = {2 , 3 , 4 , 3 , 4 , 4};

bool vis[10];

bool check()
{
	for(int i = 1 ; i <= 4 ; ++ i)
		for(int j = 1 ; j <= 4 ; ++ j)
			d[i][j] = 0;
	for(int i = 0 ; i < 6 ; ++ i)
		if(vis[i]) d[b[i]][c[i]] = d[c[i]][b[i]] = 1;
	int p[5];
	for(int i = 1 ; i <= n ; ++ i)
		p[i] = i;
	do
	{

		bool flag = true;
		for(int i = 1 ; i <= n ; ++ i)
			for(int j = 1 ; j <= n ; ++ j)
				if(a[i][j] ^ d[p[i]][p[j]]) flag = false;
		if(flag)
		{
			// for(int i = 0 ; i < 6 ; ++ i)
			// 	printf("%d " , vis[i]);
			// puts("");
			return true;
		}
	}while(next_permutation(p + 1 , p + 1 + n));
	return false;
}

int dfs(int now)
{
	if(now == 6) return check();
	int ret = 0;
	vis[now] = false; ret = dfs(now + 1);
	vis[now] = true; ret += dfs(now + 1) , vis[now] = false;
	return ret;
}

bool force()
{
	for(int i = 1 ; i <= n ; ++ i)
		for(int j = 1 ; j <= n ; ++ j)
			a[i][j] = 0;
	for(int i = 1 ; i <= m ; ++ i)
	{
		int x = read() , y = read();
		a[x][y] = a[y][x] = 1;
	}
	if(n <= 3) return true;
	return dfs(0) <= n;
}

bool solve()
{
	scanf("%d%d", &n, &m);
	if(n <= 4) return force();
	for(int i = 1; i <= n; i ++) deg[i] = 0;
	for(int i = 1; i <= m; i ++)
	{
		int u, v;
		scanf("%d%d", &u, &v);
		deg[u] ++;
		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);
	for(int i = 1 ; i <= T ; ++ i)
	{
		if(solve()) puts("YES");
		else puts("NO");
		if (T == 28572 && i == 34) {printf("%d\n" , n);}
	}
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 1ms
memory: 5880kb

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: 0
Accepted
time: 13ms
memory: 5936kb

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:

YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
...

result:

ok 39982 token(s): yes count is 39982, no count is 0

Test #3:

score: 0
Accepted
time: 230ms
memory: 5800kb

input:

33365
3 3
3 1
2 3
2 1
2 1
2 1
4 6
1 2
3 4
4 2
2 3
3 1
4 1
2 1
1 2
2 1
1 2
4 5
1 4
1 2
4 2
3 4
1 3
4 3
4 2
2 1
1 3
3 1
3 2
4 3
1 3
1 2
3 4
3 3
3 2
3 1
2 1
3 1
2 3
3 1
1 3
3 1
2 1
3 2
1 3
3 2
4 5
3 1
4 2
3 4
2 3
2 1
4 2
1 2
3 2
2 1
2 1
3 2
1 2
2 3
3 1
3 2
4 1
3 4
3 1
2 1
4 3
1 2
4 2
3 2
2 1
2 1
4 5
3 ...

output:

YES
YES
YES
YES
YES
NO
NO
YES
NO
YES
YES
YES
YES
YES
NO
NO
YES
YES
YES
NO
YES
YES
YES
NO
YES
YES
YES
YES
YES
YES
YES
YES
NO
NO
YES
YES
YES
YES
NO
NO
NO
YES
YES
YES
YES
YES
YES
YES
YES
NO
YES
YES
YES
YES
YES
YES
NO
YES
NO
YES
YES
YES
NO
YES
YES
NO
YES
NO
YES
NO
YES
YES
YES
YES
NO
YES
YES
YES
YES
YES
...

result:

ok 33365 token(s): yes count is 25608, no count is 7757

Test #4:

score: -100
Wrong Answer
time: 159ms
memory: 6004kb

input:

28572
3 3
1 3
2 1
3 2
2 1
1 2
4 1
4 2
3 2
1 2
2 3
5 2
4 3
4 2
2 1
2 1
3 1
1 3
5 10
1 3
3 5
1 2
4 3
4 5
4 1
5 1
4 2
2 5
3 2
4 4
2 1
1 3
2 4
1 4
2 1
1 2
4 4
1 3
4 2
4 1
2 1
4 3
1 4
3 1
4 2
5 2
2 1
4 5
4 1
3 4
5 5
2 5
3 1
4 1
2 3
1 5
5 3
5 4
3 5
2 3
4 1
4 3
3 2
2 3
1 2
2 1
2 1
4 5
3 2
3 4
4 1
3 1
2 1
3...

output:

YES
YES
NO
YES
NO
YES
YES
YES
NO
YES
NO
NO
NO
NO
NO
NO
NO
YES
YES
NO
YES
NO
YES
YES
YES
NO
YES
YES
NO
YES
YES
YES
NO
NO
5
YES
NO
YES
YES
NO
NO
YES
NO
YES
NO
YES
YES
YES
YES
NO
YES
YES
NO
NO
NO
YES
YES
NO
YES
YES
NO
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
NO
YES
YES
YES
NO
NO
NO
YES
YES
Y...

result:

wrong answer expected YES, found NO [34th token]