QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#202003 | #5160. Kebab Pizza | Team_name | WA | 2ms | 24020kb | C++20 | 1.7kb | 2023-10-05 18:18:06 | 2023-10-05 18:18:07 |
Judging History
answer
#include <bits/stdc++.h>
#define endl '\n'
#define DEBUG_VAR(x) { cerr << "* "#x" = " << x << endl; }
#define DEBUG_FMT(...) { cerr << "* "; fprintf(stderr, __VA_ARGS__); }
using namespace std;
using LL = long long;
const int N = 4e5+5;
int m, n;
int deg[N];
set<int> e[N];
// vector<int> e[N];
bool vis[N];
void topsort()
{
queue<int> q;
for(int i = n; i >= 1; i--) {
if(deg[i] <= 1) {
if(i <= n/2 && deg[i+n/2] == deg[i] && deg[i] == 1)
continue;
q.push(i);
vis[i] = true;
}
}
while(q.size()) {
int x = q.front(); q.pop();
for(int y : e[x]) {
e[y].erase(x);
deg[y]--;
// if(deg[y] <= 1 && !vis[y]) {
// q.push(y);
// vis[y] = true;
// }
}
}
}
bool ins[N];
int cnt = 0, cnt_times = 0;
void dfs(int x, int fa)
{
if(ins[x]) cnt++;
if(vis[x]) return;
vis[x] = true;
ins[x] = true;
for(int y : e[x]) {
if(fa == y) continue;
dfs(y, x);
}
ins[x] = false;
}
int main()
{
// freopen("1.in", "r", stdin);
ios::sync_with_stdio(false); cin.tie(nullptr);
cin >> m >> n;
for(int i = 1; i <= m; i++) {
int x, y;
cin >> x >> y;
if(x == y) {
e[x].insert(x+n); e[x+n].insert(x);
} else {
e[x].insert(y); e[y].insert(x);
}
}
n = 2*n;
for(int x = 1; x <= n; x++) {
deg[x] = e[x].size();
}
topsort();
for(int i = 1; i <= n; i++) {
if(vis[i]) continue;
if(deg[i] > 2) {
cout << "impossible" << endl;
return 0;
}
}
for(int i = 1; i <= n; i++) {
if(!vis[i]) {
dfs(i, -1);
cnt_times++;
}
}
if(cnt == 0 || (cnt_times == cnt && cnt == 1)) {
cout << "possible" << endl;
return 0;
} else {
cout << "impossible" << endl;
return 0;
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 24020kb
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: 22348kb
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: 23964kb
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: 22504kb
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: 0ms
memory: 23052kb
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: 22364kb
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: 23932kb
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: 22464kb
input:
4 5 1 2 3 4 4 5 5 3
output:
possible
result:
wrong answer 1st lines differ - expected: 'impossible', found: 'possible'