QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#88796 | #5745. Graph Isomorphism | galaxias | WA | 201ms | 6064kb | C++14 | 1.8kb | 2023-03-17 14:37:51 | 2023-03-17 14:37:55 |
Judging History
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 <= 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);
while(T --)
if(solve()) puts("YES");
else puts("NO");
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 5736kb
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: 15ms
memory: 6064kb
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: -100
Wrong Answer
time: 201ms
memory: 5712kb
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 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:
wrong answer expected NO, found YES [6th token]