QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#432590#8686. Zoo ManagementzhutianruiWA 2ms9892kbC++202.3kb2024-06-07 12:52:082024-06-07 12:52:08

Judging History

你现在查看的是最新测评结果

  • [2024-06-07 12:52:08]
  • 评测
  • 测评结果:WA
  • 用时:2ms
  • 内存:9892kb
  • [2024-06-07 12:52:08]
  • 提交

answer

#include <bits/stdc++.h>
#define int long long

#define F(i, a, b) for (int i = (a); i <= (b); i++)
#define dF(i, a, b) for (int i = (a); i >= (b); i--)
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;

const int N = 400005, M = (N << 1), inf = 1e16, mod = 1e9 + 7, B = 1e7 + 7;
mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());
const int msk = rnd();
int n, m, a[N], pre[N], to[N], dcc[N], cdcc, ec[N], vi[N];
vector<int> G[N], ve[N], now, p;
int s[N], top, dfn[N], low[N], cnt;
void pop(int v) {
    cdcc ++;
    do {
        dcc[s[top]] = cdcc;
        ve[cdcc].push_back(s[top]);
    } while (s[top --] != v);
}
void tarjan(int u, int fa = 0) {
    dfn[u] = low[u] = ++cnt, s[++top] = u;
    for (auto v : G[u]) {
        if (v == fa) continue; 
        if (!dfn[v]) {
            tarjan(v, u);
            low[u] = min(low[u], low[v]);
            if (low[v] > dfn[u]) pop(v);
        } else {
            low[u] = min(low[u], dfn[v]);
        }
    }
    if (!fa) pop(u);
}
signed main() {
    scanf("%lld%lld", &n, &m);
    F(i, 1, n) {
        scanf("%lld%lld", pre + i, to + i);
    }
    F(i, 1, m) {
        int u, v;
        scanf("%lld%lld", &u, &v);
        G[u].push_back(v);
        G[v].push_back(u);
    }
    F(i, 1, n) {
        if (!dfn[i]) {
            tarjan(i);
        }
    }
    F(i, 1, cdcc) {
        map<int, int> x;
        for (auto j : ve[i]) {
            x[pre[j]] ^= 1;
            x[to[j]] ^= 1;
        }
        for (auto j : x) {
            if (j.second) 
                puts("impossible"), exit(0);
        }
    }
    F(i, 1, n)
        for (auto j : G[i])
            if (dcc[i] == dcc[j])
                ec[dcc[i]] ++;
    F(i, 1, cdcc) {
        if (ec[i] / 2 != ve[i].size()) continue ;
        ull x = 0, y = 0, pw = 1;
        vector<int> num = ve[i];
        for (auto j : ve[i]) num.push_back(j), x = x * B + pre[j], y = y * B + to[j];
        F(j, 1, ve[i].size() - 1) pw *= B;
        for (int j = 1; j < ve[i].size() && y != x; j ++) {
            y -= pw * to[ve[i][j - 1]], y = y * B + to[ve[i][j - 1]];
        }
        // cerr << x << ' ' << y << endl;
        if (x != y) puts("impossible"), exit(0);
    }
    puts("possible");
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 2ms
memory: 9760kb

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: 2ms
memory: 9892kb

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'