QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#66147 | #5160. Kebab Pizza | feeder1# | WA | 5ms | 5884kb | C++14 | 1.2kb | 2022-12-07 01:23:39 | 2022-12-07 01:23:40 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef long double ld;
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define nl "\n"
#define all(v) v.begin(),v.end()
int n, m, t, a, b, c;
set<pii> s;
int cnt[100005];
vector<int> v[100005];
bool vis[100005];
bool gd;
void dfs(int x, int par) {
vis[x] = true;
for (auto it : v[x]) {
if (it == par) continue;
if (vis[it]) gd = true;
else dfs(it, x);
}
}
int main(){
ios::sync_with_stdio(0);
cin.tie(0);
cin >> n >> m;
for (int i=0; i<n; i++) {
cin >> a >> b;
if (a > b) swap(a,b);
s.insert(mp(a, b));
}
for (auto it : s) {
int x = it.first, y = it.second;
cnt[x]++, cnt[y]++;
}
for (auto it : s) {
int x = it.first, y = it.second;
if (x == y) continue;
if (cnt[y] > 1 && cnt[x] > 1) {
v[x].pb(y);
v[y].pb(x);
}
}
for (int i=1; i<=m; i++) {
if (v[i].size() > 2) {
cout << "impossible";
return 0;
}
}
int cnt = 0;
for (int i=1; i<=m; i++) {
if (!vis[i] && v[i].size()) {
dfs(i, -1);
cnt++;
}
}
if (gd && cnt > 1) cout << "impossible";
else cout << "possible";
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 5ms
memory: 5784kb
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: 5636kb
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: 2ms
memory: 5692kb
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: 4ms
memory: 5700kb
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: 5ms
memory: 5884kb
input:
4 4 1 2 2 1 3 4 4 3
output:
possible
result:
ok single line: 'possible'
Test #6:
score: 0
Accepted
time: 5ms
memory: 5692kb
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: 5692kb
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: 1ms
memory: 5704kb
input:
4 5 1 2 3 4 4 5 5 3
output:
possible
result:
wrong answer 1st lines differ - expected: 'impossible', found: 'possible'