QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#124873 | #5160. Kebab Pizza | jzh# | WA | 1ms | 3492kb | C++14 | 2.0kb | 2023-07-15 17:16:10 | 2023-07-15 17:16:14 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
int n, k; cin >> n >> k;
vector<int>d(k+1), cnt(k+1);
vector<vector<int>>g(k+1);
vector<int>vis(k+1);
for(int i = 1 ; i <= n ; i ++) {
int a, b; cin >> a >> b;
if(a==b) {
cnt[a]++;
}
else {
g[a].push_back(b);
g[b].push_back(a);
d[a]++, d[b]++;
}
vis[a] = vis[b] = true;
}
vector<int>del;
for(int i = 1 ; i <= k ; i ++) {
if(cnt[i]==0 and d[i]==1 and d[g[i][0]]>2) {
del.push_back(i);
}
}
auto update = [&](int i) {
int v = g[i][0];
d[i]--;
d[v]--;
for(int j = 0 ; j < g[v].size() ; j ++) {
if(g[v][j]==i) {
g[v].erase(g[v].begin()+j);
break;
}
}
g[i].pop_back();
vis[i] = false;
};
for(auto &i: del) update(i);
for(int i = 1 ; i <= k ; i ++) {
if(d[i]>2) {
cout << "impossible\n";
return 0;
}
}
int tot = accumulate(begin(vis), end(vis), 0);
if(d==vector<int>(k+1, 0)) {
cout << "possible\n";
return 0;
}
for(int i = 1 ; i <= k ; i ++) {
if(d[i]==2) {
bool flag = true;
int now = g[i][0], pre = i, len = 1;
while(now!=i) {
++len;
if(d[now]==1) {
flag = false;
break;
}
if(g[now][0]==pre) {
pre = now;
now = g[now][1];
}
else {
pre = now;
now = g[now][0];
}
}
if(flag and len!=tot) {
cout << "impossible\n";
return 0;
}
}
}
cout << "possible\n";
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 3492kb
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: 1ms
memory: 3464kb
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: 1ms
memory: 3440kb
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: -100
Wrong Answer
time: 1ms
memory: 3404kb
input:
8 4 1 1 1 2 2 1 2 2 3 3 3 4 4 3 4 4
output:
impossible
result:
wrong answer 1st lines differ - expected: 'possible', found: 'impossible'