QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#566525 | #9319. Bull Farm | lllei | WA | 0ms | 3628kb | C++20 | 6.1kb | 2024-09-16 00:22:27 | 2024-09-16 00:22:27 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
int n, l, q;
int calc(char a, char b) {
return (a - 48) * 50 + (b - 48);
}
using B = bitset<2001>;
int main() {
cin.tie(0);
ios::sync_with_stdio(0);
int T;
cin >> T;
while (T--) {
cin >> n >> l >> q;
vector<string> s(l + 1);
vector<vector<array<int, 3>>> c(l + 1);
for (int i = 1; i <= l; i++) {
cin >> s[i];
}
for (int i = 1; i <= q; i++) {
string t;
cin >> t;
c[calc(t[4], t[5])].push_back({calc(t[0], t[1]), calc(t[2], t[3]), i});
}
vector<int> ans(q + 1);
vector<vector<int>> e(n + 1);
vector<int> id(n + 1);
iota(id.begin(), id.end(), 0);
for (auto [x, y, id] : c[0]) {
if (x == y) {
ans[id] = 1;
} else {
ans[id] = 0;
}
}
for (int i = 1; i <= l; i++) {
vector<int> nxt(n + 1);
vector<int> pre(n + 1);
vector<int> du(n + 1);
for (int j = 0; j < n; j++) {
int u = j + 1, v = calc(s[i][j * 2], s[i][j * 2 + 1]);
du[v]++;
pre[v] = u;
nxt[u] = v;
}
int cnt = 0;
for (int j = 1; j <= n; j++) {
if (du[j] == 0) {
cnt++;
}
}
vector<bool> vis(n + 1);
vector<int> dfn(n + 1), low(n + 1);
int cntt = 0;
vector<int> stk(n + 1);
int top = 0;
int tot = 0;
vector<int> idd(n + 1);
auto tarjan = [&](auto &&self, int u) -> void {
dfn[u] = low[u] = ++cntt;
vis[u] = true;
stk[++top] = u;
for (int v : e[u]) {
if (!dfn[v]) {
self(self, v);
low[u] =min(low[u], low[v]);
} else if (vis[v]) {
low[u] = min(low[u], dfn[v]);
}
}
if (low[u] == dfn[u]) {
tot++;
int x;
do {
x = stk[top];
vis[x] = false;
top--;
idd[x] = tot;
} while (x != u);
}
};
if (cnt == 0) {
for (int i = 1; i <= n; ++i) {
int t = nxt[i];
if (id[t] != id[i]) {
e[id[t]].push_back(id[i]);
}
}
} else if (cnt == 1) {
int u = -1, v = -1;
for (int i = 1; i <= n; ++i) {
if (du[i] == 0) {
u = i;
} else if (du[i] == 2) {
v = i;
}
}
int x = v;
while (nxt[v] != x) {
v = nxt[v];
}
if (id[v] != id[u]) {
e[id[u]].push_back(id[v]);
}
int t1 = u;
while (nxt[t1] != x) {
t1 = nxt[t1];
}
if (id[t1] != id[u]) {
e[id[u]].push_back(id[t1]);
}
} else {
}
for (int i = 1; i <= n; ++i) {
if (!dfn[id[i]]) {
tarjan(tarjan, id[i]);
}
}
vis.assign(n + 1, 0);
vector<vector<int>> ee(n + 1);
for (int i = 1; i <= n; ++i) {
if (!vis[id[i]]) {
continue;
}
vis[id[i]] = true;
int u = id[i];
for (int v : e[u]) {
int t1 = idd[u];
int t2 = idd[v];
if (t1 != t2 && !vis[t2]) {
ee[t1].push_back(t2);
vis[t2] = true;
}
}
for (int v : e[u]) {
int t2 = idd[v];
vis[t2] = false;
}
}
e = move(ee);
for (int i = 1; i <= n; ++i) {
id[i] = idd[id[i]];
assert(id[i] != 0);
}
vector<B> b(n + 1);
vector<int> dd(n + 1);
for (int i = 1; i <= n; ++i) {
if (id[i] == i) {
b[i][i] = true;
for (int v : e[i]) {
dd[v]++;
}
}
}
queue<int> q;
vis.assign(n + 1, 0);
for (int i = 1; i <= n; ++i) {
if (!vis[id[i]] && dd[i] == 0) {
id[i] = true;
q.push(id[i]);
}
}
while (q.size()) {
int u = q.front();
q.pop();
for (int v : e[u]) {
b[v] |= b[u];
dd[v]--;
if (dd[v] == 0) {
q.push(v);
}
}
}
for (auto [u, v, idd] : c[i]) {
u = id[u];
v = id[v];
if (b[u][v]) {
ans[idd] = 1;
} else {
ans[idd] = 0;
}
}
}
for (int i = 1; i <= q; ++i) {
cout << ans[i];
}
cout << '\n';
}
}
/*
1
6 2 4
030603010601
010203060504
030202
060402
050602
060401
1
3 3 2
020202
030301
030201
020303
010202
*/
详细
Test #1:
score: 0
Wrong Answer
time: 0ms
memory: 3628kb
input:
2 5 2 4 0305040201 0404040404 030300 020500 050102 020501 6 2 4 030603010601 010203060504 030202 060402 050602 060401
output:
1011 1111
result:
wrong answer 2nd lines differ - expected: '0100', found: '1111'