QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#270872#5160. Kebab Pizzaucup-team173#WA 3ms8688kbC++201.9kb2023-12-01 16:57:362023-12-01 16:57:37

Judging History

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

  • [2023-12-01 16:57:37]
  • 评测
  • 测评结果:WA
  • 用时:3ms
  • 内存:8688kb
  • [2023-12-01 16:57:36]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
#define mpr make_pair
#define pb push_back
#define fi first
#define se second

const int maxn=111111;
int n, k;
vector<int>v[maxn];
vector<int>g[maxn];

int f[maxn];
int getf(int x){
    return x==f[x]?x:(f[x]=getf(f[x]));
}
void check1(){
    for(int i=1;i<=n;i++){
        if(v[i].size()<=1)continue;
        f[i]=i;
        if(g[i].size()!=2)return;
    }
    for(int i=1;i<=n;i++){
        if(v[i].size()<=1)continue;        
        f[getf(i)]=getf(g[i][0]);
        f[getf(i)]=getf(g[i][1]);
    }
    set<int>s;
    for(int i=1;i<=n;i++){
        if(v[i].size()<=1)continue;
        s.insert(getf(i));
    }
    if(s.size()<=1){
        cout<<"possible";
        exit(0);
    }
}
void check2(){
    for(int i=1;i<=n;i++){
        if(v[i].size()<=1)continue;
        f[i]=i;
    }
    for(int i=1;i<=n;i++){
        if(v[i].size()<=1)continue;
        int x,y;
        for(int j:g[i]){
            if(j>i)continue;
            x=getf(i);
            y=getf(j);
            if(x==y)return;
            f[x]=y;
        }
    }
    cout<<"possible";
    exit(0);
}
signed main(){
    ios::sync_with_stdio(0);
    cin.tie(0),cout.tie(0);
    cin >> n >> k;
    for(int i = 1; i <= n; i++) {
        int a,b;
        cin >> a >> b;
        if(a!=b)
        v[a].pb(b),v[b].pb(a);
    }    
    for(int i=1;i<=n;i++){
        sort(v[i].begin(),v[i].end());
        v[i].resize(unique(v[i].begin(),v[i].end())-v[i].begin());
    }   
    for(int i=1;i<=n;i++){
        if(v[i].size()>1){
            for(int j:v[i]){
                if(v[j].size()>1)g[i].pb(j);
            }
        }
    }
    for(int i=1;i<=n;i++){
        if(v[i].size()>1&&g[i].size()>2){
            cout<<"impossible\n";
            return 0;
        }
    }
    check1(),check2();
    cout<<"impossible\n";
    return 0;
}

詳細信息

Test #1:

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

input:

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

output:

possible

result:

ok single line: 'possible'

Test #2:

score: 0
Accepted
time: 3ms
memory: 8576kb

input:

5 5
1 3
1 5
2 3
2 5
3 4

output:

possible

result:

ok single line: 'possible'

Test #3:

score: 0
Accepted
time: 3ms
memory: 8668kb

input:

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

output:

impossible

result:

ok single line: 'impossible'

Test #4:

score: 0
Accepted
time: 0ms
memory: 8688kb

input:

8 4
1 1
1 2
2 1
2 2
3 3
3 4
4 3
4 4

output:

possible

result:

ok single line: 'possible'

Test #5:

score: 0
Accepted
time: 3ms
memory: 8680kb

input:

4 4
1 2
2 1
3 4
4 3

output:

possible

result:

ok single line: 'possible'

Test #6:

score: 0
Accepted
time: 0ms
memory: 8604kb

input:

5 4
1 1
1 4
2 2
2 4
3 4

output:

possible

result:

ok single line: 'possible'

Test #7:

score: -100
Wrong Answer
time: 0ms
memory: 8616kb

input:

6 4
1 1
1 4
2 2
2 4
3 3
3 4

output:

possible

result:

wrong answer 1st lines differ - expected: 'impossible', found: 'possible'