QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#655445 | #6679. Not Another Path Query Problem | sh-sho1kat | WA | 1ms | 3976kb | C++20 | 1.9kb | 2024-10-19 04:47:43 | 2024-10-19 04:47:44 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define double long double
#define pii pair<int, int>
#define tii array<int, 3>
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define accu(x) accumulate(all(x), (int)0)
int n, m, q, V;
vector<tii> edges;
struct dsu
{
int par[100005];
int find(int x)
{
if (par[x] == 0 || par[x] == x)
return par[x] = x;
return par[x] = find(par[x]);
}
void join(int x, int y)
{
x = find(x);
y = find(y);
if (x == y)
return;
par[x] = y;
}
} pre[65];
signed main()
{
ios_base::sync_with_stdio(0);
cin.tie(NULL);
cin >> n >> m >> q >> V;
for (int i = 1; i <= m; i++)
{
int u, v, w;
cin >> u >> v >> w;
edges.push_back({u, v, w});
}
int curr = 0;
for (int i = 61; i >= 0; i--)
{
bool temp = 0;
if ((V >> i) & 1)
{
curr |= 1LL << i;
}
else
{
temp = 1;
curr |= 1LL << i;
}
if (temp)
{
for (auto it = edges.begin(); it != edges.end(); ++it)
{
int u = (*it)[0], v = (*it)[1], w = (*it)[2];
if ((w & curr) == curr)
{
pre[i].join(u, v);
}
}
curr ^= 1LL << i;
}
}
while (q--)
{
int u, v;
cin >> u >> v;
bool hobe = 0;
for (int i = 61; i >= 0; i--)
{
if (pre[i].find(u) == pre[i].find(v))
{
hobe = 1;
break;
}
}
if (hobe)
cout << "Yes\n";
else
cout << "No\n";
}
return 0;
}
詳細信息
Test #1:
score: 100
Accepted
time: 1ms
memory: 3976kb
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: 1ms
memory: 3924kb
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]