QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#196965 | #5160. Kebab Pizza | RobeZH# | RE | 1ms | 3628kb | C++14 | 1.8kb | 2023-10-02 05:40:00 | 2023-10-02 05:40:00 |
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) {
// cout << "del " << i << " " <<
G[to].erase(i);
G[i].clear();
}
}
// rep(i, 0, n) {
// for (int x : G[i]) cout << i << " " << x << endl;
// }
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];
// cout << tsum << endl;
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: 1ms
memory: 3452kb
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: 3448kb
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: 3432kb
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: 1ms
memory: 3480kb
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: 3508kb
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: 3508kb
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: 3496kb
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: 0ms
memory: 3556kb
input:
4 5 1 2 3 4 4 5 5 3
output:
impossible
result:
ok single line: 'impossible'
Test #9:
score: 0
Accepted
time: 0ms
memory: 3444kb
input:
4 4 1 1 2 3 3 4 4 2
output:
impossible
result:
ok single line: 'impossible'
Test #10:
score: 0
Accepted
time: 0ms
memory: 3548kb
input:
3 4 1 2 2 3 3 1
output:
possible
result:
ok single line: 'possible'
Test #11:
score: 0
Accepted
time: 0ms
memory: 3480kb
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: 3400kb
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: 0ms
memory: 3448kb
input:
4 3 1 2 2 3 3 1 1 1
output:
possible
result:
ok single line: 'possible'
Test #14:
score: 0
Accepted
time: 0ms
memory: 3448kb
input:
6 6 1 2 2 3 3 1 4 5 5 6 6 4
output:
impossible
result:
ok single line: 'impossible'
Test #15:
score: 0
Accepted
time: 0ms
memory: 3512kb
input:
4 6 1 2 2 3 4 5 5 6
output:
possible
result:
ok single line: 'possible'
Test #16:
score: 0
Accepted
time: 0ms
memory: 3420kb
input:
4 8 1 2 3 4 5 6 7 8
output:
possible
result:
ok single line: 'possible'
Test #17:
score: 0
Accepted
time: 0ms
memory: 3448kb
input:
3 3 1 2 2 3 1 2
output:
possible
result:
ok single line: 'possible'
Test #18:
score: 0
Accepted
time: 0ms
memory: 3480kb
input:
13 11 11 7 8 6 4 8 1 2 6 7 6 2 2 9 3 8 11 8 6 11 8 2 9 1 9 11
output:
impossible
result:
ok single line: 'impossible'
Test #19:
score: 0
Accepted
time: 1ms
memory: 3628kb
input:
1635 131 40 13 22 72 98 70 81 118 124 122 90 12 24 5 86 61 45 75 91 80 14 1 28 74 84 27 120 83 75 117 44 130 127 38 58 64 22 17 12 48 107 87 37 131 41 15 11 48 5 46 127 50 123 75 43 124 93 5 17 83 26 130 66 122 55 105 36 119 116 49 98 89 73 86 119 99 16 24 39 90 33 72 94 22 19 13 101 9 116 8 33 95 8...
output:
impossible
result:
ok single line: 'impossible'
Test #20:
score: -100
Runtime Error
input:
1803 1766 967 1468 1305 1669 617 36 1564 714 53 1045 1536 80 467 373 375 1173 1750 210 1433 81 667 798 1345 825 274 85 1107 1425 1576 560 30 405 1324 129 612 332 506 1708 87 1587 337 891 503 786 1140 304 1439 966 841 234 1270 696 1557 1607 763 1422 196 461 1485 557 1509 44 511 1050 623 1587 687 1758...