QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#140913 | #5160. Kebab Pizza | RetiredButNotTired# | WA | 4ms | 18308kb | C++17 | 1.4kb | 2023-08-16 23:08:35 | 2023-08-16 23:08:37 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
#define ll long long
int tt, tc;
const int N = 2e5 + 5, mod = 1e9 + 7;
set<int> tmpAdj[N];
vector<int> adj[N];
int n, k, vis[N];
bool dfs(int u, int p = -1) {
if (vis[u]) return true;
vis[u] = 1;
int ret = 0;
for (auto v: adj[u]) if (v != p) ret |= dfs(v, u);
return ret;
}
void solve() {
cin >> n >> k;
for (int i = 0; i < n; ++i) {
int u, v;
cin >> u >> v;
tmpAdj[u].insert(v);
tmpAdj[v].insert(u);
}
for (int i = 1; i <= k; ++i) if (tmpAdj[i].empty() || tmpAdj[i].size() == 1 && *tmpAdj[i].begin() != i) vis[i] = 1;
for (int u = 1; u <= k; ++u) {
if (vis[u]) continue;
for (auto v: tmpAdj[u])
if (!vis[v] && v != u)
adj[u].push_back(v);
if (adj[u].size() > 2) return void(cout << "impossible" << endl);
}
int cmps = 0, cycle = 0;
for (int i = 1; i <= k; ++i) {
if (vis[i]) continue;
cmps++;
cycle |= dfs(i);
}
if ((cmps > 1) + cycle > 1) cout << "impossible" << endl;
else cout << "possible" << endl;
}
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
tt = 1, tc = 1; //cin >> tt;
while (tt--) solve(), tc++;
}
详细
Test #1:
score: 100
Accepted
time: 0ms
memory: 17716kb
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: 18308kb
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: 17536kb
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: 17864kb
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: 17660kb
input:
4 4 1 2 2 1 3 4 4 3
output:
possible
result:
ok single line: 'possible'
Test #6:
score: 0
Accepted
time: 1ms
memory: 17492kb
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: 4ms
memory: 18180kb
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: 17560kb
input:
4 5 1 2 3 4 4 5 5 3
output:
possible
result:
wrong answer 1st lines differ - expected: 'impossible', found: 'possible'