QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#201976 | #5160. Kebab Pizza | DreamOn# | WA | 1ms | 3576kb | C++23 | 1.5kb | 2023-10-05 18:00:39 | 2023-10-05 18:00:40 |
Judging History
answer
#include <iostream>
#include <cstring>
#include <cstdio>
#include <cmath>
#define Maxn 100005
using namespace std;
int n, m, deg[Maxn];
struct Edge {
int next, to;
}
edge[Maxn * 2];
int head[Maxn], edge_num;
void add_edge(int from, int to) {
edge[++edge_num].next = head[from];
edge[edge_num].to = to;
head[from] = edge_num;
}
bool vis[Maxn]; int maxdeg, mindeg;
void dfs(int u) {
vis[u] = 1;
maxdeg = max(maxdeg, deg[u]);
mindeg = min(mindeg, deg[u]);
for(int i = head[u]; i; i = edge[i].next) {
int v = edge[i].to;
if(vis[v]) continue;
dfs(v);
}
}
int main() {
scanf("%d%d", &m, &n);
int u, v;
for(int i = 1; i <= m; ++i) {
scanf("%d%d", &u, &v);
if(u == v) continue;
add_edge(u, v); add_edge(v, u);
++deg[u]; ++deg[v];
}
for(int i = 1; i <= n; ++i) {
if(deg[i] == 1) vis[i] = 1, --deg[i]; --deg[edge[head[i]].to];
}
int cnt1 = 0, cnt2 = 0, cnt3 = 0;
for(int i = 1; i <= n; ++i) {
maxdeg = 0; mindeg = n + 1;
if(!vis[i]) dfs(i);
if(maxdeg == 2 && mindeg == 2) ++cnt2;
else if(maxdeg == 2 && mindeg == 1) ++cnt1;
else if(maxdeg <= 1 && mindeg <= 1) ++cnt1;
else ++cnt3;
}
// cout << cnt1 << " " << cnt2 << " " << cnt3 << endl;
if(cnt3 || (cnt2 > 1) || (cnt2 && cnt1)) cout << "impossible" << endl;
else cout << "possible" << endl;
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Wrong Answer
time: 1ms
memory: 3576kb
input:
7 6 2 2 3 6 1 1 1 5 4 5 6 6 6 5
output:
impossible
result:
wrong answer 1st lines differ - expected: 'possible', found: 'impossible'