QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#207920 | #5160. Kebab Pizza | Minhho | WA | 2ms | 8936kb | C++20 | 1.6kb | 2023-10-08 23:01:50 | 2023-10-08 23:01:50 |
Judging History
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;
return 0;
}
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)
{
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(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: 8324kb
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: -100
Wrong Answer
time: 0ms
memory: 8936kb
input:
5 5 1 3 1 5 2 3 2 5 3 4
output:
impossible
result:
wrong answer 1st lines differ - expected: 'possible', found: 'impossible'