QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#190406 | #6679. Not Another Path Query Problem | JWRuixi# | WA | 0ms | 30404kb | C++20 | 2.6kb | 2023-09-28 20:35:55 | 2023-09-28 20:35:56 |
Judging History
answer
#include <bits/stdc++.h>
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2")
// #define ATC
#define LL long long
#define eb emplace_back
using namespace std;
#ifdef ATC
#include <atcoder/all>
using namespace atcoder;
#endif
mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());
const int mod = 998244353;
namespace mystd {
typedef pair<int, int> pii;
#define fi first
#define se second
#define MP make_pair
template<typename T, typename _T>
inline void inc (T &x, const _T &y) { x += y; (x >= mod) && (x -= mod); }
template<typename T, typename _T>
inline void dec (T &x, const _T &y) { x -= y; (x < 0) && (x += mod); }
template<typename T, typename _T>
inline void cmax (T &x, const _T &y) { (x < y) && (x = y); }
template<typename T, typename _T>
inline void cmin (T &x, const _T &y) { (x > y) && (x = y); }
template<typename T>
inline void write (const T &Arg) { cout << Arg; }
template<typename T, typename ..._T>
inline void write (const T &Arg, const _T &...Args) { cout << Arg, write(Args...); }
template<typename T>
inline void read (T &Arg) { cin >> Arg; }
template<typename T, typename ..._T>
inline void read (T &Arg, _T &...Args) { cin >> Arg, read(Args...); }
}
using namespace mystd;
const int N = 1e5 + 5, M = 64;
int n, m, q;
LL V;
vector<pii> G[N];
struct DSU {
int par[N];
inline void init (int o) {
iota(par + 1, par + o + 1, 1);
}
inline int find (int x) {
return x == par[x] ? x : par[x] = find(par[x]);
}
inline void merge (int x, int y) {
x = find(x), y = find(y);
if (x == y) return;
par[x] = y;
}
inline bool same (int x, int y) {
return find(x) == find(y);
}
} d[M];
int main() {
ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
cin >> n >> m >> q >> V;
for (int i = 1, u, v, w; i <= m; i++) {
cin >> u >> v >> w;
G[u].eb(v, w);
G[v].eb(u, w);
}
for (int i = 61; ~i; i--)
d[i].init(n);
for (int i = 61; ~i; i--) {
if (V >> i & 1 ^ 1) {
LL x = ((V >> i) << i) + (1LL << i);
for (int u = 1; u <= n; u++)
for (auto [v, w] : G[u])
if ((w & x) == x)
d[i].merge(u, v);
}
}
while (q--) {
static int u, v;
cin >> u >> v;
bool fl = 0;
for (int i = 0; i <= 61; i++) fl |= d[i].same(u, v);
cout << (fl ? "Yes\n" : "No\n");
}
#if LOCAL
cout.flush();
#endif
}
// I love WHQ!
详细
Test #1:
score: 100
Accepted
time: 0ms
memory: 30244kb
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:
Yes No Yes No
result:
ok 4 token(s): yes count is 2, no count is 2
Test #2:
score: -100
Wrong Answer
time: 0ms
memory: 30404kb
input:
3 4 1 4 1 2 3 1 2 5 2 3 2 2 3 6 1 3
output:
No
result:
wrong answer expected YES, found NO [1st token]