QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#505251#5745. Graph IsomorphismchimeraWA 381ms3816kbC++141.8kb2024-08-04 23:32:282024-08-04 23:32:28

Judging History

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

  • [2024-08-04 23:32:28]
  • 评测
  • 测评结果:WA
  • 用时:381ms
  • 内存:3816kb
  • [2024-08-04 23:32:28]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
#define ll long long

int main() {
    ll T; cin >> T;
    for(ll t = 0; t < T; t++) {
        ll N, M; cin >> N >> M;

        vector<vector<ll>> adj(N);
        for(ll i = 0; i < M; i++) {
            ll U,V; cin >> U >> V; U--;V--;
            adj[U].push_back(V); adj[V].push_back(U);
        }

        if(N <= 3) {
            cout << "YES\n"; continue;
        }

        // complete graph: always fail.
        if(M == (N*(N-1))/2 || M == 0) {
            cout << "YES\n"; continue;
        }

        map<ll,ll> counts;
        for(ll i = 0; i < N; i++) counts[adj[i].size()]++;

        bool star = (counts[1]== N-1);
        bool clique = (counts[N-2]== N-1);
        if(star || clique) {
            cout << "YES\n"; continue;
        }

        // if there is a vertex with degree in the range [2..N-2], now always possible; (N-1 choose 2) > N

        if(N > 5) {
            // in big graphs even if all vertices are small, there are enough matchings.
            cout << "NO\n"; continue;
        }

        vector<vector<pair<ll,ll>>> results;

        vector<ll> permu;
        for(ll i = 0; i < N; i++) permu.push_back(i);

        do {
            vector<pair<ll,ll>> ed;
            for(ll i = 0; i < N; i++) {
            for(auto a: adj[i]) {
                ed.push_back({permu[i], permu[a]});
            }
            }

            sort(ed.begin(), ed.end());

            bool contained = false; for(auto r: results) if(r == ed) contained = true;

            if(!contained) results.push_back(ed);
        } while(next_permutation(permu.begin(), permu.end()));

        if(results.size() > N) cout << "NO\n";
        else cout << "YES\n";
        


        
    }
}

详细

Test #1:

score: 100
Accepted
time: 0ms
memory: 3476kb

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: 23ms
memory: 3516kb

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: 89ms
memory: 3808kb

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: 381ms
memory: 3816kb

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
YES
NO
NO
NO
NO
YES
YES
NO
YES
NO
YES
YES
YES
NO
YES
YES
NO
YES
YES
YES
NO
YES
YES
NO
YES
YES
NO
NO
YES
YES
YES
NO
YES
YES
YES
YES
NO
YES
YES
YES
NO
NO
YES
YES
YES
YES
YES
NO
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
NO
YES
YES
YES
NO
NO
NO
YES
YE...

result:

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