QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#276934#5307. Subgraph IsomorphismhazeWA 29ms3532kbC++202.6kb2023-12-06 13:18:162023-12-06 13:18:17

Judging History

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

  • [2023-12-06 13:18:17]
  • 评测
  • 测评结果:WA
  • 用时:29ms
  • 内存:3532kb
  • [2023-12-06 13:18:16]
  • 提交

answer

/*
Author: haze
2023/12/6
12:52
*/

#include <bits/stdc++.h>

#define irep(i, l, r) for(int (i) = (l); (i) <= (r); ++(i))
#define drep(i, r, l) for(int (i) = (r); (i) >= (l); --(i))
#define ll long long
#define ull unsigned long long
#define LL __int128
using namespace std;

inline ll read() {
    char ch = getchar();
    ll s = 0;
    bool w = 0;
    while (!isdigit(ch)) {
        if (ch == '-')w = 1;
        ch = getchar();
    }
    while (isdigit(ch))s = (s << 3) + (s << 1) + (ch ^ 48), ch = getchar();
    return w ? -s : s;
}

inline char rc() {
    char ch = getchar();
    while (1) {
        if (ch >= '!' && ch <= '~')return ch;
        ch = getchar();
    }
}

template<class T1, class T2>
T1 min(T1 AA, T2 BB) { return AA > BB ? BB : AA; }

template<class T1, class T2>
T1 max(T1 AA, T2 BB) { return AA < BB ? BB : AA; }

const int itinf = 1e9;
const ll llinf = 4e18;
const int mod = 1000000007;
const int N = 500009;
const ull mask = chrono::steady_clock::now().time_since_epoch().count();
bool solve(){
    int n = read(), m = read();
    vector<vector<int>>g(n);
    vector<int>deg(n);
    irep(i, 0, m - 1){
        int u = read() - 1, v = read() - 1;
        g[u].emplace_back(v);
        g[v].emplace_back(u);
        deg[u] ++, deg[v] ++;
    }
    if(m == n - 1)return true;
    if(m > n)return false;
    stack<int>st;
    irep(i, 0, n - 1){
        if(deg[i] == 1)
            st.push(i);
    }
    while(st.size()){
        int x = st.top();
        st.pop();
        for(int y : g[x]){
            deg[y] --;
            if(deg[y] == 1)
                st.push(y);
        }
    }
    vector<int>vis(n);
    irep(i, 0, n - 1){
        if(deg[i] == 2)
            vis[i] = 1;
    }
    auto shift = [](ull x) -> ull{
        x ^= mask;
        x ^= x << 13;
        x ^= x >> 7;
        x ^= x << 17;
        x ^= mask;
        return x;
    };
    function<ull(int)> hs = [&](int x) -> ull{
        ull key = 7;
        vis[x] = 1;
        for(int y : g[x]){
            if(! vis[y]){
                key += shift(hs(y));
            }
        }
        return key;
    };
    ull se = 0;
    bool fl = 0;
    irep(i, 0, n - 1){
        if(deg[i] == 2){
            if(fl == 0)fl = 1, se = hs(i);
            else if(se != hs(i))return false;
        }
    }
    return true;
}

int main() {
    int T = read();
    while(T --){
        puts(solve() ? "YES" : "NO");
    }
    return 0;
}
/*
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
 */

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

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: 29ms
memory: 3532kb

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
NO
NO
NO
NO
NO
NO
YES
NO
NO
NO
YES
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
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 [39th token]