QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#75420#5307. Subgraph Isomorphismteam1377#WA 66ms6248kbC++144.1kb2023-02-05 10:02:432023-02-05 10:02:45

Judging History

你现在查看的是测评时间为 2023-02-05 10:02:45 的历史记录

  • [2023-10-15 17:24:14]
  • 管理员手动重测本题所有提交记录
  • 测评结果:WA
  • 用时:49ms
  • 内存:6312kb
  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-02-05 10:02:45]
  • 评测
  • 测评结果:0
  • 用时:66ms
  • 内存:6248kb
  • [2023-02-05 10:02:43]
  • 提交

answer

#include <bits/stdc++.h>

using namespace std;

const int N = 1e5 + 5;

vector<int> G[N];
int dep[N];

void dfs(int x)
{
    for (int i = 0; i < G[x].size(); ++i) {
        if (!dep[G[x][i]]) {
            dep[G[x][i]] = dep[x] + 1;
            dfs(G[x][i]);
        }
    }
    return;
}

int dis(int x, int y)
{
    memset(dep, 0, sizeof(dep));
    dep[x] = 1;
    dfs(x);
    return dep[y] - 1;
}

signed main()
{
    int T;
    scanf("%d", &T);
    while (T--) {
        int n, m;
        scanf("%d%d", &n, &m);
        for (int i = 1; i <= n; ++i) {
            G[i].clear();
        }
        for (int i = 1; i <= m; ++i) {
            int x, y;
            scanf("%d%d", &x, &y);
            G[x].push_back(y);
            G[y].push_back(x);
        }
        if (m == n - 1) {
            puts("YES");
        } else if (m != n) {
            puts("NO");
        } else {
            int flag = 1;
            for (int i = 1; i <= n; ++i) {
                if (G[i].size() != 2) {
                    flag = 0;
                    break;
                }
            }
            if (flag) {
                puts("YES");
            } else {
                if ((n & 1) || n < 6) {
                    puts("NO");
                    continue;
                }
                int wh1 = 0, wh2 = 0;
                for (int i = 1; i <= n; ++i) {
                    if (G[i].size() == 1) {
                        if (!wh1) {
                            wh1 = i;
                        } else {
                            if (!wh2) {
                                wh2 = i;
                            } else {
                                wh2 = -1;
                                break;
                            }
                        }
                    }
                }
                if (!~wh2 || !wh2) {
                    puts("NO");
                } else {
                    int wh3 = 0, wh4 = 0;
                    for (int i = 1; i <= n; ++i) {
                        if (G[i].size() == 3) {
                            if (!wh3) {
                                wh3 = i;
                            } else {
                                if (!wh4) {
                                    wh4 = i;
                                } else {
                                    wh4 = -1;
                                    break;
                                }
                            }
                        }
                    }
                    if (!~wh4 || !wh4) {
                        puts("NO");
                    } else {
                        int wh5 = 0, wh6 = 0;
                        for (int i = 1; i <= n; ++i) {
                            if (G[i].size() == 2 && ((G[i][0] == wh3 && G[i][1] == wh4) || (G[i][0] == wh4 && G[i][1] == wh3))) {
                                if (!wh5) {
                                    wh5 = i;
                                } else {
                                    if (!wh6) {
                                        wh6 = i;
                                    } else {
                                        wh6 = -1;
                                        break;
                                    }
                                }
                            }
                        }
                        if (!~wh6 || !wh6) {
                            puts("NO");
                        } else {
                            flag = 1;
                            for (int i = 1; i <= n; ++i) {
                                flag &= (G[i].size() <= 3);
                            }
                            if (flag && dis(wh1, wh2) == n - 2 && ((dis(wh1, wh3) == n / 2 - 2 && dis(wh2, wh4) == n / 2 - 2) || (dis(wh1, wh4) == n / 2 - 2 && dis(wh2, wh3) == n / 2 - 2))) {
                                puts("YES");
                            } else {
                                puts("NO");
                            }
                        }
                    }
                }
            }
        }
    }
    return 0;
}

详细

Test #1:

score: 100
Accepted
time: 3ms
memory: 5776kb

input:

4
7 6
1 2
2 3
3 4
4 5
5 6
3 7
3 3
1 2
2 3
3 1
5 5
1 2
2 3
3 4
4 1
1 5
1 0

output:

YES
YES
NO
YES

result:

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

Test #2:

score: -100
Wrong Answer
time: 66ms
memory: 6248kb

input:

33192
2 1
1 2
3 2
1 3
2 3
3 3
1 2
1 3
2 3
4 3
1 4
2 4
3 4
4 3
1 3
1 4
2 4
4 4
1 3
1 4
2 4
3 4
4 4
1 3
1 4
2 3
2 4
4 5
1 3
1 4
2 3
2 4
3 4
4 6
1 2
1 3
1 4
2 3
2 4
3 4
5 4
1 5
2 5
3 5
4 5
5 4
1 4
1 5
2 5
3 5
5 5
1 4
1 5
2 5
3 5
4 5
5 5
1 4
1 5
2 4
3 5
4 5
5 5
1 4
1 5
2 4
2 5
3 5
5 6
1 4
1 5
2 4
2 5
3 ...

output:

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

result:

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