QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#784792 | #3570. Guards | SGColin# | 0 | 108ms | 4064kb | C++20 | 2.2kb | 2024-11-26 15:57:44 | 2024-11-26 15:57:45 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
#define pb push_back
#define eb emplace_back
#define all(s) (s).begin(), (s).end()
#define rep(i, a, b) for (int i = (a); i <= (b); ++i)
#define per(i, a, b) for (int i = (a); i >= (b); --i)
constexpr int N = 10007;
int tot, bel[N], spv[N], f[N], g[N];
bool sp[N];
vector<int> sta[N];
vector<pii> e[N];
void dfs(int u) { // {min(all), min(spv is selected)}
for (auto [x, y] : e[u]) dfs(bel[y]);
f[u] = g[u] = INT_MAX;
for (auto s : sta[u]) {
int cst = __builtin_popcount(s);
for (auto [x, y] : e[u]) {
cst += (((s >> x) & 1) ? f[bel[y]] : g[bel[y]]);
}
if (u == 1) f[u] = min(f[u], cst);
else {
f[u] = min(f[u], cst);
if ((s >> spv[u]) & 1) g[u] = min(g[u], cst);
}
}
}
void add_block(int n, int m, int w) {
int cur = ++tot;
e[cur].clear();
sta[cur].clear();
vector<int> V;
vector<pii> E;
rep(i, 1, m) {
int u, v;
cin >> u >> v;
bel[u] = bel[v] = cur;
V.eb(u); V.eb(v); E.eb(u, v);
}
sort(all(V));
V.erase(unique(all(V)), V.end());
auto getpos = [&](int w) {
return lower_bound(all(V), w) - V.begin();
};
auto ok = [&](int S) {
for (auto [u, v] : E) {
u = getpos(u); v = getpos(v);
if (!((S >> u) & 1) && !((S >> v) & 1)) return false;
}
return true;
};
rep(S, 0, (1 << V.size()) - 1) if (ok(S)) sta[cur].eb(S);
for (auto p : V) if (sp[p]) spv[cur] = getpos(p);
rep(i, 1, w) {
int u, v;
cin >> u >> v;
u = getpos(u);
e[cur].eb(u, v);
int nn, mm, ww;
cin >> nn >> mm >> ww;
add_block(nn, mm, ww);
}
};
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
int n, m, w;
while (cin >> n >> m >> w) {
tot = 0;
memset(bel, 0, sizeof(bel));
memset(sp, 0, sizeof(sp));
add_block(n, m, w);
dfs(1);
printf("%d\n", f[1]);
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Pretests
Final Tests
Test #1:
score: 0
Wrong Answer
time: 108ms
memory: 4064kb
input:
5 8 2 1 2 2 4 3 4 1 3 1 5 2 5 3 5 4 5 1 6 3 3 0 6 7 7 8 8 6 5 10 3 2 2 10 11 10 12 11 13 2 1 0 13 9 11 14 3 2 0 14 15 14 16 5 8 2 1 2 2 4 3 4 1 3 1 5 2 5 3 5 4 5 2 7 3 3 0 7 9 7 8 8 9 3 11 3 2 0 11 12 11 13 5 4 2 2 1 3 2 4 1 5 4 4 8 5 4 0 7 6 8 6 9 6 10 9 5 15 5 4 0 12 11 13 11 14 12 15 12 5 4 2 2 1...
output:
8 6 6 6 7 8 7 9 10 10 11 9 9 9 8 11 12 12 13 15 11 10 12 13 14 13 15 15 17 13 11 15 15 17 16 18 18 20 8 9 9 9 9 11 11 12 12 10 10 12 14 14 15 15 16 16 14 13 15 16 15 19 19 20 21 14 15 17 16 22 23 23 24 25 9 12 10 12 10 13 12 14 15 10 11 13 15 16 17 19 19 21 14 15 19 20 20 21 23 25 24 19 21 22 19 23 ...
result:
wrong answer 3rd lines differ - expected: '7', found: '6'