QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#166950#6861. Counter StrikePPP#WA 554ms24924kbC++173.9kb2023-09-06 21:33:372023-09-06 21:33:38

Judging History

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

  • [2023-09-06 21:33:38]
  • 评测
  • 测评结果:WA
  • 用时:554ms
  • 内存:24924kb
  • [2023-09-06 21:33:37]
  • 提交

answer

#ifdef DEBUG
#define _GLIBCXX_DEBUG
#endif
//#pragma GCC optimize("O3")
#include<bits/stdc++.h>

using namespace std;
typedef long long ll;
typedef long double ld;
const int mod = 998244353;

int mult(int a, int b) {
    return (1LL * a * b) % mod;
}

int sub(int a, int b) {
    int s = a - b;
    if (s < 0) s += mod;
    return s;
}

int pw(int a, int b) {
    if (b == 0) return 1;
    if (b & 1) return mult(a, pw(a, b - 1));
    int res = pw(a, b / 2);
    return mult(res, res);
}

int sum(int a, int b) {
    int s = a + b;
    if (s >= mod) s -= mod;
    return s;
}

int n, m, k;
const int maxN = 2e5 + 10;
vector<int> g[maxN];
int h[maxN];
bool good[maxN];
bool used[maxN];
bool mrk[maxN];
int ROOT = -1;
int has_bad[maxN];
int mn[maxN];
int S = 1e9;

void dfs(int v, int p) {
    used[v] = true;
    mn[v] = h[v];
    for (int to: g[v]) {
        if (good[to]) continue;
        if (!used[to]) {
            h[to] = h[v] + 1;
            dfs(to, v);
            mn[v] = min(mn[v], mn[to]);
        } else if (h[to] < h[v] - 1) {
            mn[v] = min(mn[v], h[to]);
        }
    }
    if (v == ROOT) {
        if (has_bad[v] <= 1) {
            S = 0;
            return;
        }
        bool ok = true;
        for (int to: g[v]) {
            if (good[to]) continue;
            if (h[to] == h[v] + 1) {
                ok &= (has_bad[to] <= 1);
            }
        }
        if (ok) {
            S = min(S, 1);
        }
    } else {
        bool ok = true;
        if (has_bad[ROOT] - has_bad[v] > 1) return;
        for (int to: g[v]) {
            if (good[to]) continue;
            if (h[to] == h[v] + 1) {
                if (has_bad[to] == 0) continue;
                ok &= (has_bad[to] <= 1);
                if (mn[to] < h[v]) {
                    ok = false;
                    break;
                }
            }
        }
        if (ok) {
            S = min(S, 1);
        }
    }
}

void dfs_prec(int v, int p) {
    has_bad[v] = mrk[v];
    used[v] = true;;
    for (int to: g[v]) {
        if (good[to]) continue;
        if (!used[to]) {
            dfs_prec(to, v);
            has_bad[v] += has_bad[to];
        }
    }
}

void solve() {
    cin >> n >> m >> k;
    for (int i = 1; i <= n; i++) {
        g[i].clear();
        mrk[i] = false;
    }
    for (int i = 1; i <= m; i++) {
        int u, v;
        cin >> u >> v;
        g[u].emplace_back(v);
        g[v].emplace_back(u);
    }
    for (int i = 1; i <= k; i++) {
        cin >> h[i];
        mrk[h[i]] = true;
    }
    int L = -1;
    int R = k;
    auto check = [&](int mid) {
        for (int i = 1; i <= n; i++) {
            good[i] = false;
            used[i] = false;
        }
        for (int i = 1; i <= mid; i++) {
            good[h[i]] = true;
        }
        int CNT = 0;
        for (int i = 1; i <= n; i++) {
            if (!used[i] && !good[i] && mrk[i]) {
                dfs_prec(i, -1);
            }
        }
        for (int i = 1; i <= n; i++) {
            used[i] = false;
        }
        for (int i = 1; i <= n; i++) {
            if (!used[i] && !good[i] && mrk[i]) {
                ROOT = i;
                h[i] = 0;
                S = 1e9;
                dfs(i, -1);
//                cout << i << " " << CNT << " " << S << endl;
                CNT += S;
                if (CNT >= 2) break;
            }
        }
        return CNT <= 1;
    };
//    check(0);
//    exit(0);
    while (R - L > 1) {
        int mid = (L + R) / 2;
        if (check(mid)) R = mid;
        else L = mid;
    }
    cout << R << '\n';
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
#ifdef DEBUG
    freopen("input.txt", "r", stdin);
#endif
    int tst;
    cin >> tst;
    while (tst--) {
        solve();
    }
    return 0;
}

详细

Test #1:

score: 0
Wrong Answer
time: 554ms
memory: 24924kb

input:

4446
21 23 21
21 20
19 10
6 11
9 21
18 9
14 1
18 11
14 2
19 15
17 11
6 2
19 17
3 16
1 7
5 11
17 4
10 20
13 16
13 3
13 8
9 11
12 13
12 18
12 3 13 4 10 11 6 1 14 9 15 21 8 19 18 5 16 17 7 20 2
24 28 24
19 15
2 11
20 18
19 17
8 6
3 10
21 18
22 6
21 10
14 6
14 7
5 19
2 23
5 10
1 11
12 20
13 16
24 3
10 9...

output:

21
24
10
4
10
2
20
16
18
23
14
18
4
9
15
16
8
13
21
19
18
0
9
0
18
15
3
0
18
2
17
22
15
19
12
12
17
12
21
20
13
14
5
10
16
17
0
25
21
21
1
1
22
13
11
15
19
24
15
3
2
16
16
11
0
5
21
3
20
23
16
20
17
16
0
14
23
22
15
20
22
18
2
17
12
8
6
0
13
15
18
14
25
22
16
19
24
0
7
11
20
10
14
0
16
8
17
3
11
14
...

result:

wrong answer 1st lines differ - expected: '12', found: '21'