QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#182638#5745. Graph Isomorphismucup-team1209#TL 338ms5664kbC++201.5kb2023-09-18 11:55:192023-09-18 11:55:19

Judging History

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

  • [2023-09-18 11:55:19]
  • 评测
  • 测评结果:TL
  • 用时:338ms
  • 内存:5664kb
  • [2023-09-18 11:55:19]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
#define rep(i,x,y) for (int i=(x);i<=(y);i++)
#define drep(i,y,x) for (int i=(y);i>=(x);i--)
#define pii pair<int,int>
#define fir first
#define sec second
#define MP make_pair
#define templ template<typename T>
templ bool chkmin(T &x,T y){return x>y?x=y,1:0;}
templ bool chkmax(T &x,T y){return x<y?x=y,1:0;}
void file() {
    #ifdef zqj
    freopen("a.in","r",stdin);
    #endif
}
typedef long long ll;
#define sz 201010

int n,m;
int deg[sz],cc[sz];

void work() {
    cin>>n>>m;
    set<pii>E;
    int x,y;
    rep(i,1,m) cin>>x>>y,E.insert(minmax(x,y));
    if (n<=6) {
        static int p[sz];
        rep(i,1,n) p[i]=i;
        int cnt=0;
        do {
            set<pii>ee;
            for (auto [x,y]:E) ee.insert(minmax(p[x],p[y]));
            if (ee==E) ++cnt;
        } while (next_permutation(p+1,p+n+1));
        int fac=1; rep(i,1,n) fac*=i;
        cnt=fac/cnt;
        cout<<(cnt<=n?"YES":"NO")<<'\n';
        return; 
    }
    rep(i,0,n) deg[i]=cc[i]=0;
    for (auto [x,y]:E) ++deg[x],++deg[y];
    rep(i,1,n) ++cc[deg[i]];
    rep(i,2,n-3) if (cc[i]) {
        cout<<"NO\n";
        return;
    }
    if (cc[n-1]) swap(cc[n-1],cc[0]),swap(cc[n-2],cc[1]);
    if (cc[0]) {
        if (!cc[1]) cout<<"YES\n";
        else cout<<"NO\n";
        return;
    }
    assert(cc[1]==n||cc[n-2]==n);
    cout<<"NO\n";
}

int main() {
    file();
    ios::sync_with_stdio(false),cin.tie(0);
    int T; cin>>T;
    while (T--) work();
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

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: 11ms
memory: 5664kb

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: 60ms
memory: 3580kb

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: 338ms
memory: 3612kb

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: -100
Time Limit Exceeded

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: