QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#88627 | #5745. Graph Isomorphism | galaxias# | WA | 14ms | 5724kb | C++14 | 1.3kb | 2023-03-16 19:59:10 | 2023-03-16 19:59:13 |
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];
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]