QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#490317#6679. Not Another Path Query ProblemzhangbojuWA 0ms19728kbC++171.3kb2024-07-25 14:33:292024-07-25 14:33:30

Judging History

This is the latest submission verdict.

  • [2024-07-25 14:33:30]
  • Judged
  • Verdict: WA
  • Time: 0ms
  • Memory: 19728kb
  • [2024-07-25 14:33:29]
  • Submitted

answer

#include <bits/stdc++.h>
using namespace std;
template <typename T> inline void read(T &x) {
	short f = 1; char c = getchar(); x = 0;
	for(; c < '0' || c > '9'; c = getchar())
		if (c == '-') f = -1;
	for (; c >= '0' && c <= '9'; c = getchar())
		x = (x << 1) + (x << 3) + (c - '0');
	x *= f;
	return ;
}
constexpr int N = 5e5 + 5;
using ll = long long;
int n, m, q;
ll V;
vector<array<ll,2>> g[N];
int id[N], idx;
int a[N][2];
int stk[N], top;
void dfs(int s, ll val) {
	idx++;
	stk[++top] = s;
	while (top) {
		int u = stk[top--];
		for (auto [v, w] : g[u]) {
			if (((w & val) == val) && !id[v])
				stk[++top] = v, id[v] = idx;
		}
	}
}
bool ans[N];
void check(ll val) {
	for (int i = 1; i <= n; i++)
		id[i] = 0;
	idx = 0;
	for (int i = 1; i <= n; i++)
		if (!id[i])
			dfs(i, val);
	for (int i = 1; i <= q; i++)
		ans[i] |= id[a[i][0]] == id[a[i][1]];
}
signed main() {
	read(n), read(m), read(q), read(V);
	for (int i = 1; i <= m; i++) {
		int u, v;
		ll w;
		read(u), read(v), read(w);
		g[u].push_back({v, w});
		g[v].push_back({u, w});
	}
	for (int i = 1; i <= q; i++) 
		read(a[i][0]), read(a[i][1]);
	if (!V) check(V);
	else {
		for (ll t = V; t < (1ll << 60); t += (t & (-t)))
			check(t);
	}
	for (int i = 1; i <= q; i++)
		puts(ans[i] ? "Yes" : "No");
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Wrong Answer
time: 0ms
memory: 19728kb

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
Yes
Yes
Yes

result:

wrong answer expected NO, found YES [2nd token]