QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#419067 | #8686. Zoo Management | light_ink_dots | WA | 5ms | 22788kb | C++14 | 2.2kb | 2024-05-23 17:27:41 | 2024-05-23 17:27:42 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
int main() {
static const int maxn = 400010;
int n, m;
scanf("%d %d", &n, &m);
static int b[maxn], e[maxn];
for (int i = 1; i <= n; i++) scanf("%d %d", b + i, e + i);
static vector<int> G[maxn];
while (m--) {
int x, y;
scanf("%d %d", &x, &y);
G[x].push_back(y);
G[y].push_back(x);
}
static vector<int> vec[maxn];
static int bel[maxn], siz[maxn], cnt;
function<void(int, int)> tarjan = [&tarjan](const int u, const int fa) {
static stack<int> S;
static int dfn[maxn], low[maxn], c;
S.push(u), dfn[u] = low[u] = ++c;
for (int i : G[u])
if (i != fa) {
if (!dfn[i])
tarjan(i, u), low[u] = min(low[u], low[i]);
else if (!bel[i])
low[u] = min(low[u], dfn[i]);
}
if (dfn[u] == low[u]) {
int v;
cnt++;
do bel[v = S.top()] = cnt, vec[cnt].push_back(v), S.pop();
while (v != u);
}
return;
};
for (int i = 1; i <= n; i++)
if (!bel[i])
tarjan(i, 0);
for (int i = 1; i <= n; i++)
for (int j : G[i])
if (i < j && bel[i] == bel[j])
siz[bel[i]]++;
auto get = [](const vector<int>& a) {
int i = 0, j = 1, k = 0;
while (i < a.size() && j < a.size() && k < a.size()) {
int I = a[(i + k) % a.size()], J = a[(j + k) % a.size()];
I != J ? (I > J ? i : j) += k + 1, j += i == j, k = 0 : k++;
}
i = min(i, j);
vector<int> ret;
for (int p = i; p < a.size(); p++) ret.push_back(a[p]);
for (int p = 0; p < i; p++) ret.push_back(a[p]);
return ret;
};
for (int i = 1; i <= cnt; i++)
if (siz[i] == vec[i].size()) {
vector<int> B, E;
for (int u : vec[i]) B.push_back(b[u]), E.push_back(e[u]);
if (get(B) != get(E)) {
printf("impossible\n");
return 0;
}
}
printf("possible\n");
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 3ms
memory: 22788kb
input:
6 7 1 1 2 2 3 3 1 2 2 3 3 1 1 2 2 3 1 3 3 4 4 5 5 6 4 6
output:
possible
result:
ok single line: 'possible'
Test #2:
score: -100
Wrong Answer
time: 5ms
memory: 22628kb
input:
5 6 10 10 20 20 30 30 40 50 50 40 1 2 2 3 1 3 3 4 3 5 4 5
output:
possible
result:
wrong answer 1st lines differ - expected: 'impossible', found: 'possible'