QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#93800#5745. Graph Isomorphismmaomao90#TL 291ms3464kbC++173.4kb2023-04-02 16:50:072023-04-02 16:50:11

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-04-02 16:50:11]
  • 评测
  • 测评结果:TL
  • 用时:291ms
  • 内存:3464kb
  • [2023-04-02 16:50:07]
  • 提交

answer


// Hallelujah, praise the one who set me free
// Hallelujah, death has lost its grip on me
// You have broken every chain, There's salvation in your name
// Jesus Christ, my living hope
#include <bits/stdc++.h> 
using namespace std;

#define REP(i, s, e) for (int i = (s); i < (e); i++)
#define RREP(i, s, e) for (int i = (s); i >= (e); i--)
template <class T>
inline bool mnto(T& a, T b) {return a > b ? a = b, 1 : 0;}
template <class T>
inline bool mxto(T& a, T b) {return a < b ? a = b, 1: 0;}
typedef long long ll;
typedef long double ld;
#define FI first
#define SE second
typedef pair<int, int> ii;
typedef pair<ll, ll> pll;
typedef tuple<int, int, int> iii;
#define ALL(_a) _a.begin(), _a.end()
#define SZ(_a) (int) _a.size()
#define pb push_back
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<ii> vii;
typedef vector<iii> viii;

#ifndef DEBUG
#define cerr if (0) cerr
#endif

const int INF = 1000000005;
const ll LINF = 1000000000000000005ll;
const int MAXN = 200005;

int t;
int n, m;
vii eg;

int main() {
#ifndef DEBUG
    ios::sync_with_stdio(0), cin.tie(0);
#endif
    cin >> t;
    while (t--) {
        cin >> n >> m;
        eg = vii(m);
        REP (i, 0, m) {
            cin >> eg[i].FI >> eg[i].SE;
            if (eg[i].FI > eg[i].SE) {
                swap(eg[i].FI, eg[i].SE);
            }
        }
        sort(ALL(eg));
        if (m == 0 || m == (ll) n * (n - 1) / 2) {
            cout << "YES\n";
            continue;
        }
        if (n > 7) {
            cout << "NO\n";
            continue;
        }
        vi p(n, 0);
        iota(ALL(p), 1);
        set<vii> st;
        do {
            vii teg;
            for (auto [u, v] : eg) {
                int nu = p[u - 1], nv = p[v - 1];
                if (nu > nv) {
                    swap(nu, nv);
                }
                teg.pb({nu, nv});
            }
            sort(ALL(teg));
            st.insert(teg);
            if (SZ(st) > n) {
                break;
            }
        } while (next_permutation(ALL(p)));
        if (SZ(st) > n) {
            cout << "NO\n";
        } else {
            cout << "YES\n";
        }
        /*
        int ans = 0;
        REP (i, 0, 1 << (n * (n - 1) / 2)) {
            if (__builtin_popcount(i) != m) {
                continue;
            }
            int ptr = 0;
            vii neg;
            REP (j, 0, n) {
                REP (k, j + 1, n) {
                    if (i >> ptr & 1) {
                        neg.pb({j, k});
                    }
                    ptr++;
                }
            }
            assert(SZ(neg) == m);
            vi p(n, 0);
            iota(ALL(p), 1);
            bool fnd = 0;
            do {
                vii teg;
                for (auto [u, v] : neg) {
                    int nu = p[u], nv = p[v];
                    if (nu > nv) {
                        swap(nu, nv);
                    }
                    teg.pb({nu, nv});
                }
                sort(ALL(teg));
                if (teg == eg) {
                    fnd = 1;
                    break;
                }
            } while (next_permutation(ALL(p)));
            ans += fnd;
            if (ans > n) {
                break;
            }
        }
        cerr << ans << '\n';
        if (ans > n) {
            cout << "NO\n";
        } else {
            cout << "YES\n";
        }
        */
    }
    return 0;
}

详细

Test #1:

score: 100
Accepted
time: 2ms
memory: 3368kb

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: 16ms
memory: 3464kb

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: 34ms
memory: 3428kb

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: 0
Accepted
time: 86ms
memory: 3408kb

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

result:

ok 28572 token(s): yes count is 19834, no count is 8738

Test #5:

score: 0
Accepted
time: 291ms
memory: 3380kb

input:

22864
5 8
4 1
2 3
5 2
1 2
1 5
5 3
4 2
5 4
4 5
4 3
2 1
4 2
1 4
3 1
4 5
3 2
1 4
1 2
4 2
3 1
5 5
2 5
1 2
5 4
5 3
1 5
5 4
1 5
4 5
2 5
3 5
6 1
6 1
3 3
3 2
2 1
3 1
6 10
4 2
5 4
3 2
6 2
5 6
5 2
6 3
4 6
3 4
3 5
3 2
1 3
1 2
2 1
2 1
3 1
1 2
3 3
2 1
3 2
3 1
6 3
4 5
2 3
6 3
4 3
2 4
2 1
3 4
5 1
2 3
4 2
4 2
3 1
6...

output:

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

result:

ok 22864 token(s): yes count is 14940, no count is 7924

Test #6:

score: -100
Time Limit Exceeded

input:

17284
5 7
2 3
4 5
5 2
2 1
1 5
3 5
1 3
4 4
4 3
1 3
2 4
4 1
2 1
2 1
2 1
1 2
3 2
2 1
3 2
2 1
1 2
3 1
3 1
7 15
3 7
7 6
2 5
1 5
1 7
3 6
2 7
5 6
1 6
3 5
6 2
2 3
5 7
3 1
1 2
7 18
2 7
1 5
4 7
5 4
4 3
1 7
4 1
7 3
1 3
3 2
1 2
2 5
1 6
2 4
7 6
5 6
6 4
2 6
5 4
2 4
4 3
4 1
5 4
3 1
2 3
3 1
1 3
7 15
7 3
7 5
5 4
4 1...

output:

NO
NO
YES
YES
YES
YES
YES
YES
NO
YES
YES
YES
YES
YES
NO
YES
YES
NO
YES
YES
NO
YES
YES
YES
YES
YES
NO
NO
YES
YES
YES
YES
YES
YES
NO
YES
YES
NO
YES
NO
YES
YES
NO
YES
YES
YES
YES
YES
YES
YES
NO
NO
NO
NO
NO
NO
NO
YES
NO
NO
YES
YES
YES
NO
YES
NO
YES
YES
NO
NO
NO
NO
YES
YES
NO
YES
YES
YES
NO
YES
YES
YES
Y...

result: