QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#217137 | #6679. Not Another Path Query Problem | 1722087564 | WA | 7ms | 124144kb | C++20 | 2.2kb | 2023-10-16 15:35:11 | 2023-10-16 15:35:11 |
Judging History
answer
#include <bits/stdc++.h>
using i64 = long long;
const int M = 61;
struct DSU {
int n;
std::vector<int> fa;
DSU(int n) {
this->n = n;
fa.resize(n + 1);
std::iota(fa.begin(), fa.end(), 0);
}
int find(int x) {
return fa[x] == x ? x : fa[x] = find(fa[x]);
}
bool merge(int x, int y) {
x = find(x);
y = find(y);
if (x == y) {
return false;
}
fa[y] = x;
return true;
}
bool same(int x, int y) {
return find(x) == find(y);
}
};
const int N = 5e5 + 10;
std::vector<DSU> dsu(M, DSU(N));
signed main() {
std::ios::sync_with_stdio(false);
std::cin.tie(nullptr);
int n, m, q;
i64 Value;
std::cin >> n >> m >> q >> Value;
// int maxd = 0;
// for (int i = 0; i < M; i++) {
// if (Value >> i & 1) {
// maxd = i;
// }
// }
for (int i = 1; i <= m; i++) {
int u, v;
i64 w;
std::cin >> u >> v >> w;
if ((w & 1) == (Value & 1) && ((w >> 1) & (Value >> 1)) == (Value >> 1)) {
dsu[0].merge(u, v);
}
for (int j = 0; j < M; j++) {
if ((w >> j & 1) && (!(Value >> j & 1)) &&
(((w >> (j + 1)) & (Value >> (j + 1))) == (Value >> (j + 1)))) {
dsu[j].merge(u, v);
}
}
}
while (q--) {
int u, v;
std::cin >> u >> v;
/*ans = "No";
for (int i = M - 1; i > maxd; i--) {
if (dsu[i].same(u, v)) {
ans = "Yes";
break;
}
}
if (ans == "Yes") {
std::cout << ans << "\n";
continue;
}*/
std::string ans = "No";
for (int i = M - 1; i >= 0; i--) {
if (!dsu[i].same(u, v) && (Value >> i & 1)) {
ans = "No";
break;
}
if (dsu[i].same(u, v) && (i == 0 || !(Value >> i & 1))) {
ans = "Yes";
break;
}
}
std::cout << ans << "\n";
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Wrong Answer
time: 7ms
memory: 124144kb
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]