QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#281813 | #6679. Not Another Path Query Problem | kernel_panic | WA | 2ms | 9900kb | C++14 | 2.0kb | 2023-12-10 20:57:25 | 2023-12-10 20:57:25 |
Judging History
answer
#include <cstdio>
#include <utility>
#include <vector>
#define debug(...) fprintf(stderr, __VA_ARGS__)
#define int long long
inline int rd() {
int x = 0, f = 1, c = getchar();
while (((c - '0') | ('9' - c)) < 0)
f = c != '-', c = getchar();
while (((c - '0') | ('9' - c)) > 0)
x = x * 10 + c - '0', c = getchar();
return f ? x : -x;
}
using pii = std::pair<int, int>;
const int N = 1e5;
const int M = 5e5;
const int LOGN = 61;
int n, m, q, V;
struct edge {
int u, v, w;
} e[M + 5];
pii qu[M + 5];
bool win[M + 5], ans[M + 5];
std::vector<int> g[N + 5];
int col[N + 5], cid;
void dfs(int u, int c) {
col[u] = c;
for (int v : g[u]) {
if (!col[v]) dfs(v, c);
}
}
signed main() {
n = rd(), m = rd(), q = rd(), V = rd();
for (int i = 1; i <= m; i++) e[i] = {rd(), rd(), rd()};
for (int i = 1; i <= q; i++) qu[i] = {rd(), rd()}, ans[i] = true;
for (int p = LOGN; p >= 0; p--) {
int S = V >> p;
for (int i = 1; i <= m; i++) {
auto [u, v, w] = e[i];
int T = w >> p;
if ((w >> p & 1) && (T & S) == S) g[u].emplace_back(v), g[v].emplace_back(u);
}
for (int i = 1; i <= n; i++) {
if (!col[i]) dfs(i, ++cid);
}
int c = V >> p & 1;
if (!c) {
for (int i = 1; i <= q; i++) {
auto [u, v] = qu[i];
if (col[u] == col[v]) {
// debug("%d, %d\n", p, i);
win[i] = true;
}
}
} else {
for (int i = 1; i <= q; i++) {
auto [u, v] = qu[i];
if (col[u] != col[v] && !win[i]) {
// debug("%d, %d\n", p, i);
ans[i] = false;
}
}
}
for (int i = 1; i <= n; i++) col[i] = 0, g[i].clear();
cid = 0;
}
for (int i = 1; i <= m; i++) {
auto [u, v, w] = e[i];
if ((V & w) == V) g[u].emplace_back(v), g[v].emplace_back(u);
}
for (int i = 1; i <= n; i++) {
if (!col[i]) dfs(i, ++cid);
}
for (int i = 1; i <= q; i++) {
auto [u, v] = qu[i];
if (col[u] != col[v]) ans[i] = false;
}
for (int i = 1; i <= q; i++) {
puts(ans[i] ? "Yes" : "No");
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Wrong Answer
time: 2ms
memory: 9900kb
input:
9 8 4 5 1 2 8 1 3 7 2 4 1 3 4 14 2 5 9 4 5 7 5 6 6 3 7 15 1 6 2 7 7 6 1 8
output:
No No No No
result:
wrong answer expected YES, found NO [1st token]