QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#166992 | #6861. Counter Strike | PPP# | AC ✓ | 578ms | 25548kb | C++17 | 4.1kb | 2023-09-06 22:20:29 | 2023-09-06 22:20:29 |
Judging History
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];
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;
assert(has_bad[ROOT] > has_bad[v]);
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;
}
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;
}
int CNT = 0;
for (int i = 1; i <= n; i++) {
if (!used[i] && !good[i] && mrk[i]) {
ROOT = i;
H[i] = 0;
S = 1e9;
dfs(i, -1);
CNT += S;
if (CNT >= 2) break;
}
}
// cout << " GOT " << CNT << endl;
return CNT <= 1;
};
// check(2);
// exit(0);
// check(0);
// exit(0);
while (R - L > 1) {
int mid = (L + R) / 2;
// cout << L << " " << R << " " << mid << endl;
if (check(mid)) {
// cout << " GOOD " << endl;
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;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 578ms
memory: 25548kb
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:
12 19 8 4 5 2 15 12 12 18 13 13 4 6 10 11 7 13 15 12 11 0 5 0 11 10 3 0 12 1 15 15 12 11 11 7 13 7 15 12 8 14 4 6 12 11 0 17 18 16 1 1 15 11 6 10 12 18 11 3 2 11 9 12 0 5 16 3 11 15 11 14 12 14 0 15 12 16 9 14 15 10 1 18 11 4 3 0 8 11 11 11 19 16 12 13 19 0 7 11 15 5 14 0 14 4 13 2 8 12 12 0 17 16 1...
result:
ok 4446 lines