QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#270884#5160. Kebab Pizzaucup-team173#WA 2ms8756kbC++201.9kb2023-12-01 17:12:132023-12-01 17:12:15

Judging History

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

  • [2023-12-01 17:12:15]
  • 评测
  • 测评结果:WA
  • 用时:2ms
  • 内存:8756kb
  • [2023-12-01 17:12:13]
  • 提交

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);
    }    
    n=k;
    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;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

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: 2ms
memory: 8604kb

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: 0ms
memory: 8704kb

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: 2ms
memory: 8664kb

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: 2ms
memory: 8684kb

input:

4 4
1 2
2 1
3 4
4 3

output:

possible

result:

ok single line: 'possible'

Test #6:

score: 0
Accepted
time: 2ms
memory: 8600kb

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: 8756kb

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'