QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#207895#5160. Kebab PizzaMinhhoWA 2ms9712kbC++201.4kb2023-10-08 22:09:212023-10-08 22:09:21

Judging History

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

  • [2023-10-08 22:09:21]
  • 评测
  • 测评结果:WA
  • 用时:2ms
  • 内存:9712kb
  • [2023-10-08 22:09:21]
  • 提交

answer

#define taskname "K"
#include <bits/stdc++.h>
#define ii pair<int,int>
#define ff first
#define ss second

using namespace std;
const int maxn = 1e5 + 10;
vector<int> adj[maxn], adj2[maxn];
ii a[maxn];
int n, m, bn[maxn], col[maxn];

bool DFS(int u, int p = 0)
{
    if (col[u] == 0) col[u] = 1;
    for (int v: adj2[u]) if (v != p && col[v] < 2)
    {
        if (col[v] == 1) return 1;
        if (col[v] == 0 && DFS(v)) return 1;
    }
    col[u] = 2;
    return 0;
}

signed main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr); cout.tie(nullptr);
    cin>>m>>n;
    for (int i=1; i<=m; i++)
    {
        cin>>a[i].ff>>a[i].ss;
        adj[a[i].ff].emplace_back(a[i].ss),
        adj[a[i].ss].emplace_back(a[i].ff);
    }
    for (int i=1; i<=n; i++)
        sort(adj[i].begin(), adj[i].end()),
        adj[i].resize(unique(adj[i].begin(), adj[i].end()) - adj[i].begin());
    for (int i=1; i<=n; i++)
        for (int j: adj[i])
            if (adj[j].size() >= 2)
            {
                bn[i]++;
                adj2[i].emplace_back(j);
                adj2[j].emplace_back(i);
                if (bn[i] > 2) return cout<<"impossible", 0;
            }
    for (int i=1; i<=n; i++) if (adj[i].size() >= 2) return cout<<(DFS(i) ? "possible" : "impossible"), 0;
    cout<<"possible";
}
/**
7 6
2 2
3 6
1 1
1 5
4 5
6 6
6 5
**/

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

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

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

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: 1ms
memory: 8780kb

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: 1ms
memory: 8752kb

input:

4 4
1 2
2 1
3 4
4 3

output:

possible

result:

ok single line: 'possible'

Test #6:

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

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: 1ms
memory: 8380kb

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: -100
Wrong Answer
time: 0ms
memory: 9712kb

input:

4 5
1 2
3 4
4 5
5 3

output:

possible

result:

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