QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#196963 | #5160. Kebab Pizza | RobeZH# | WA | 3ms | 14732kb | C++14 | 1.6kb | 2023-10-02 05:32:25 | 2023-10-02 05:32:25 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define trav(a, x) for(auto& a : x)
#define all(x) begin(x), end(x)
#define sz(x) (int)(x).size()
#define subnb true
#define Lnb true
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
const int N = (int)2e5 + 50;
//const int N = 205;
int n, k;
set<int> G[N];
int sp[N];
int vis[N];
int tsum = 0;
void dfs(int v, int p, int rt, int sum) {
vis[v] = 1;
sum += sp[v];
for (int nxt : G[v]) {
if(nxt == p) continue;
if(nxt == rt) {
// found cycle
cout << ((sum + 1 == tsum) ? "possible" : "impossible") << '\n';
exit(0);
}
dfs(nxt, v, rt, sum + 1);
}
}
int main() {
ios::sync_with_stdio(false);
cin.tie(NULL);
cin >> k >> n;
rep(i, 0, k) {
int u, v; cin >> u >> v; u--, v--;
if(u == v) sp[u] = 1;
else {
G[u].insert(v);
G[v].insert(u);
}
}
vi leafs;
rep(i, 0, n) if(sz(G[i]) == 1 && !sp[i]) leafs.push_back(i);
for(int i : leafs) {
int to = *G[i].begin();
if (sz(G[to]) > 1) {
G[to].erase(i);
}
G[i].clear();
}
rep(i, 0, n) {
if(sz(G[i]) > 2) {
cout << "impossible" << endl;
return 0;
}
}
rep(i, 0, n) tsum += sz(G[i]);
tsum /= 2;
rep(i, 0, n) tsum += sp[i];
rep(i, 0, n) {
if(!vis[i]) dfs(i, -1, i, 0);
}
cout << "possible" << endl;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 3ms
memory: 13204kb
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: 14732kb
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: 12996kb
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: 0ms
memory: 13120kb
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: 2ms
memory: 13428kb
input:
4 4 1 2 2 1 3 4 4 3
output:
possible
result:
ok single line: 'possible'
Test #6:
score: 0
Accepted
time: 2ms
memory: 12992kb
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: 2ms
memory: 14220kb
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: 14268kb
input:
4 5 1 2 3 4 4 5 5 3
output:
possible
result:
wrong answer 1st lines differ - expected: 'impossible', found: 'possible'