QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#207925#5160. Kebab PizzaMinhhoWA 2ms9460kbC++201.6kb2023-10-08 23:06:052023-10-08 23:06:05

Judging History

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

  • [2023-10-08 23:06:05]
  • 评测
  • 测评结果:WA
  • 用时:2ms
  • 内存:9460kb
  • [2023-10-08 23:06:05]
  • 提交

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], st, lout;

bool DFS(int u, int p = 0)
{
//    cerr<<"IN: "<<u<<"\n";
    if (col[u] == 0) col[u] = 1;
    bool f = 0;
    for (int v: adj2[u]) if (v != p && v != u && col[v] < 2)
    {
        f = 1;
        if (col[v] == 1)
        {
            if (v == st && !lout) return 1;
        }
        if (col[v] == 0 && DFS(v, u)) return 1;
    }
    col[u] = 2;
    return (!f);
}

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++)
    {
        bool f = 0;
        for (int j: adj[i])
            if (adj[j].size() >= 2 && j != i)
            {
                bn[i]++;
                adj2[i].emplace_back(j);
                adj2[j].emplace_back(i);
                f = 1;
                if (bn[i] > 2) return cout<<"impossible", 0;
            }
        if (f == 0 && adj[i].size()) lout = 1;
    }
    for (int i=1; i<=n; i++) if (adj[i].size() >= 2) return cout<<(DFS(st = i) ? "possible" : "impossible"), 0;
    cout<<"possible";
}
/**
7 6
2 2
3 6
1 1
1 5
4 5
6 6
6 5
**/

詳細信息

Test #1:

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

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

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

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

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

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

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

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

input:

4 5
1 2
3 4
4 5
5 3

output:

impossible

result:

ok single line: 'impossible'

Test #9:

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

input:

4 4
1 1
2 3
3 4
4 2

output:

impossible

result:

ok single line: 'impossible'

Test #10:

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

input:

3 4
1 2
2 3
3 1

output:

possible

result:

ok single line: 'possible'

Test #11:

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

input:

4 3
1 2
2 3
3 1
1 2

output:

possible

result:

ok single line: 'possible'

Test #12:

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

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

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

input:

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

output:

possible

result:

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