QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#195718#5160. Kebab PizzakevinshanWA 2ms10900kbC++203.0kb2023-10-01 06:37:342023-10-01 06:37:35

Judging History

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

  • [2023-10-01 06:37:35]
  • 评测
  • 测评结果:WA
  • 用时:2ms
  • 内存:10900kb
  • [2023-10-01 06:37:34]
  • 提交

answer

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

#define ll long long
#define all(x) x.begin(), x.end()
#define pb push_back
#define mp make_pair
#define ps push
#define in insert
#define f first
#define s second
#define nl cout<<"\n"
#define ca(v) for(auto i:v) cout<<i<<" ";
#define cbit(x) __builtin_popcount(x)
#define gcd(a, b) __gcd(a, b)
#define lcm(a, b) (a*b/gcd(a, b))
int xm[4] = {-1, 1, 0, 0};
int ym[4] = {0, 0, -1, 1};
const int MOD = 1e9 + 7;
const int MAXN = 1e5 + 5;
const ll POW = 9973;


vector<int> adj[MAXN];
set<int> topp[MAXN];
int main()
{
    ios_base::sync_with_stdio(0); cin.tie(0);
    int n, k;
    cin>>n>>k;
    vector<int> contained(k,0);
    vector<int> doubled(k,0);
    vector<int> szz(k, 0);
    for(int i=0; i<n; i++){
        int u, v; cin>>u>>v;
        u--; v--;
        topp[u].in(v);
        topp[v].in(u);
        szz[u]+=1;
        szz[v]+=1;
        if(u == v) doubled[u] = 1;
    }
    for(int i=0; i<k; i++){
        if(doubled[i] == 0 && topp[i].size() == 0) contained[i] = 1;
        else if(doubled[i] == 0 && topp[i].size() == 1 && szz[*topp[i].begin()] > szz[i]) contained[i] = 1;
    }
    // for(int i=0; i<k; i++){4
    //     cout<<i<<": ";
    //     ca(topp[i]);
    //     nl;
    // }
    // ca(contained); nl;
    for(int i=0; i<k; i++){
        if(contained[i]) continue;
        for(int j:topp[i]){
            if(contained[j] || i == j) continue;
            // cout<<"E";
            adj[i].pb(j);
        }
    } 
    

    // for(int i=0; i<k; i++){
    //     cout<<i<<": ";
    //     ca(adj[i]);
    //     nl;
    // }
    vector<int> vis(k, 0);
    for(int i=0; i<k; i++){
        if(contained[i]) vis[i] = 1;
        if(adj[i].size() > 2){
            cout<<"impossible";
            return 0;
        }
    }
    // for(int i=0; i<k; i++) {
    //     ca(adj[i]);
    //     nl;
    // }
    int frog = 0;
    for(int i=0; i<k; i++){
        // if(contained[i]) vis[i] = 1;
        // if(adj[i].size() == 0) vis[i] = 1;
        if(vis[i] || adj[i].size() >= 2) continue;
        queue<int> q;
        q.push(i);
        vis[i] = 1;
        frog = 1;
        while(q.size()){
            int c = q.front();
            q.pop();
            for(int a:adj[c]){
                if(vis[a]) continue;
                vis[a] = 1;
                q.push(a);
            }
        }
    }
    // ca(vis);
    if(n == 6 && k == 6) ca(vis);
    for(int i=0; i<k; i++){
        if(vis[i]) continue;
        queue<int> q;
        q.push(i);
        if(frog){
            cout<<"impossible";
            return 0;
        }
        while(q.size()){
            int c = q.front();
            q.pop();
            for(int a:adj[c]){
                if(vis[a]) continue;
                vis[a] = 1;
                q.push(a);
            }
        }
        break;
    }
    int sm = 0;
    for(int i:vis) sm += 1;
    if(sm == k)
        cout<<"possible";
    else cout<<"impossible";

}


Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

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

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

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

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

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

input:

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

output:

possible

result:

ok single line: 'possible'

Test #7:

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

input:

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

output:

impossible

result:

ok single line: 'impossible'

Test #8:

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

input:

4 5
1 2
3 4
4 5
5 3

output:

impossible

result:

ok single line: 'impossible'

Test #9:

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

input:

4 4
1 1
2 3
3 4
4 2

output:

impossible

result:

ok single line: 'impossible'

Test #10:

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

input:

3 4
1 2
2 3
3 1

output:

possible

result:

ok single line: 'possible'

Test #11:

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

input:

4 3
1 2
2 3
3 1
1 2

output:

possible

result:

ok single line: 'possible'

Test #12:

score: 0
Accepted
time: 1ms
memory: 10616kb

input:

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

output:

impossible

result:

ok single line: 'impossible'

Test #13:

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

input:

4 3
1 2
2 3
3 1
1 1

output:

possible

result:

ok single line: 'possible'

Test #14:

score: -100
Wrong Answer
time: 1ms
memory: 10696kb

input:

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

output:

0 0 0 0 0 0 possible

result:

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