QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#54218 | #860. We apologize for any inconvenience | ckiseki# | TL | 35ms | 3616kb | C++20 | 1.3kb | 2022-10-07 16:28:32 | 2022-10-07 16:28:34 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
int main() {
cin.tie(nullptr)->sync_with_stdio(false);
int t;
cin >> t;
while (t--) {
int n, k;
cin >> n >> k;
vector<vector<int>> a(k);
for (auto &ai : a) {
int l;
cin >> l;
ai.resize(l);
for (int &aij : ai) {
cin >> aij;
--aij;
}
}
auto solve = [&] {
int r = 0;
vector<vector<int>> g(k + n);
for (int i = 0; i < k; ++i) {
for (auto j : a[i]) {
g[i].push_back(j + k);
g[j + k].push_back(i);
}
}
static constexpr int INF = 1 << 30;
for (int i = 0; i < n; ++i) {
vector<int> d(n + k, INF);
queue<int> bfs;
bfs.push(i + k);
d[i + k] = 0;
while (not bfs.empty()) {
int u = bfs.front();
bfs.pop();
if (u >= k) {
r = max(r, d[u]);
}
for (int v : g[u]) {
if (d[u] + 1 < d[v]) {
d[v] = d[u] + 1;
bfs.push(v);
}
}
}
}
return r / 2 - 1;
};
cout << solve() << '\n';
int s;
cin >> s;
while (s--) {
int x;
cin >> x;
a[x - 1].clear();
cout << solve() << '\n';
}
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 2ms
memory: 3504kb
input:
1 5 4 3 1 3 5 2 1 4 2 2 3 2 2 4 3 1 4 3
output:
1 2 0 0
result:
ok 4 number(s): "1 2 0 0"
Test #2:
score: 0
Accepted
time: 35ms
memory: 3616kb
input:
35 20 20 2 2 13 2 2 9 7 10 3 9 15 5 11 4 9 16 19 15 4 17 18 5 3 8 8 12 20 16 11 18 9 6 4 12 4 18 15 17 6 16 19 14 7 5 20 9 3 8 14 4 5 14 7 9 17 5 3 17 11 20 15 19 11 16 5 8 13 15 20 18 9 10 14 7 4 3 13 19 10 17 6 8 15 9 4 12 20 7 14 16 5 4 12 11 6 18 14 20 17 18 4 8 15 11 16 14 6 5 13 19 3 8 3 10 8 ...
output:
1 1 1 1 0 0 0 1 1 1 1 1 1 1 1 1 1 1 1 0 1 1 1 1 1 1 1 1 1 1 1 2 2 2 2 2 2 1 1 0 1 1 1 1 1 1 1 1 2 2 2 2 2 2 2 1 0 0 0 0 1 1 1 1 1 1 1 0 0 0 0 0 0 0 0 0 0 0 1 0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 0 2 1 1 1 1 1 0 0 0 0 0 0 0 0 0 0 1 1 1 0 2 2 2 2 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 0 1 1 1 1 1 1 1 0 0 0 ...
result:
ok 893 numbers
Test #3:
score: -100
Time Limit Exceeded
input:
2 750 750 2 47 500 2 51 145 2 22 531 2 22 354 2 22 727 2 25 700 2 7 159 2 42 356 2 57 727 2 28 237 2 57 714 2 68 511 2 29 81 2 65 318 2 43 91 2 65 488 2 68 549 2 16 310 2 30 618 2 6 105 2 7 468 2 34 253 2 51 155 2 21 205 2 22 470 2 36 642 2 17 649 2 66 229 2 10 409 2 65 105 2 21 395 2 51 552 2 25 55...