QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#608044#6679. Not Another Path Query ProblemSJZ2010WA 2ms12004kbC++143.1kb2024-10-03 18:02:562024-10-03 18:02:56

Judging History

This is the latest submission verdict.

  • [2024-10-03 18:02:56]
  • Judged
  • Verdict: WA
  • Time: 2ms
  • Memory: 12004kb
  • [2024-10-03 18:02:56]
  • Submitted

answer

#include <bits/stdc++.h>
using namespace std;

using LL = __int128;
using ll = long long;
using ldb = long double;
using vi = vector < int >;
using pii = pair < int, int >;
using ull = unsigned long long;
#define pb push_back
#define ve vector < edge >
#define lowbit(x) ((x) & -(x))
#define sz(x) (int((x).size()))
#define all(a) (a).begin(), (a).end()
#define me(a, b) memset(a, b, sizeof(a))
#define L(i, j, k) for (int i = j; i <= int(k); i++)
#define R(i, j, k) for (int i = j; i >= int(k); i--)
#define qio() ios::sync_with_stdio(0), cin.tie(0), cout.tie(0)
namespace io {
	int read() {
		int x = 0, f = 1; char ch = getchar();
		while (ch < '0' || ch > '9') { if (ch == '-') f = -1; ch = getchar(); }
		while (ch >= '0' && ch <= '9') {
			assert(10ll * x + (ch ^ '0') <= INT_MAX);
			x = x * 10 + (ch ^ '0'), ch = getchar();
		} return x * f;
	}
	template < class T = int > void read(T& x) {
		x = 0; int f = 1; char ch(getchar());
		while (ch < '0' || ch > '9') { if (ch == '-') f = -1; ch = getchar(); }
		while (ch >= '0' && ch <= '9') { x = x * 10 + (ch ^ '0'), ch = getchar(); } x *= f;
	}
} using io::read;

template < class T > ostream& operator << (ostream& out, vector < T > v) {
	out << '[';  if (!v.empty()) { L(i, 0, v.size() - 2) out << v[i] << ','; out << v[v.size() - 1]; } return out << ']';
}
#define DEBUG
namespace Dbg {
	template < class T > void dbg(char *f, T t) { cerr << f << '=' << t << endl; }
	template < class T, class ...Ar > void dbg(char *f, T x, Ar... y) {
		while (*f != ',') { cerr << *f++; } cerr << '=' << x << ','; dbg(f + 1, y...);
	}
}
#ifdef DEBUG
	#define gdb(...) cerr << "gdb " << __LINE__ << ": ", Dbg::dbg((char*)#__VA_ARGS__,__VA_ARGS__)
	#define debug cerr << "debug: " << __LINE__ << '\n'
	#define msg(x) cerr << x << '\n'
#else
	#define gdb(...) void()
	#define debug void()
	#define msg() void()
#endif

/* ================================= */

const int N = 1e5 + 5; // Adjust
const int M = 5e5 + 5;
const int inf = 0x3f3f3f3f;
const ll INF = 0x3f3f3f3f3f3f3f3fll;

int n, m, q, u[M], v[M], qu[M], qv[M], fa[N];
ll V, w[M];
bool ans[N];

int main() {
	n = read(), m = read(), q = read(), read(V);
	L(i, 1, m)
		u[i] = read(), v[i] = read(), read(w[i]);
	L(i, 1, q)
		qu[i] = read(), qv[i] = read();

	function < int(int) > find = [&](int x) {
		return x == fa[x] ? x : fa[x] = find(fa[x]);
	};

	if (V == 0) {
		L(i, 1, n)
			fa[i] = i;
		L(i, 1, m) {
			int fu = find(u[i]), fv = find(v[i]);
			if (fu != fv)
				fa[fu] = fv;
		}
		L(i, 1, q) 
			if (find(qu[i]) == find(qv[i]))
				puts("No");
			else
				puts("Yes");
		exit(0);
	}

	R(i, 61, 0) {
//		if (V >> i & 1)
//			continue;
		ll mask = (V != 0) ? (V | 1ll << i) : 0;
		L(j, 1, n)
			fa[j] = j;

		L(j, 1, m)
			if (((w[j] >> i) & (mask >> i)) >= (mask >> i)) {
				int fu = find(u[j]), fv = find(v[j]);
				if (fu != fv)
					fa[fu] = fv;
			}

		L(j, 1, q)
			if (find(qu[j]) == find(qv[j]))
				ans[j] = 1;

		if (V == 0)
			break;
	}

	L(i, 1, q)
		puts(ans[i] ? "Yes" : "No");
	return 0;
}

详细

Test #1:

score: 100
Accepted
time: 2ms
memory: 11824kb

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: 0
Accepted
time: 0ms
memory: 11764kb

input:

3 4 1 4
1 2 3
1 2 5
2 3 2
2 3 6
1 3

output:

Yes

result:

ok YES

Test #3:

score: -100
Wrong Answer
time: 2ms
memory: 12004kb

input:

100 2000 50000 0
32 52 69658009083393280
26 38 868250171554967916
87 32 743903879320440454
22 15 19782587273744714
57 98 845866434191429143
42 95 1145336983294966993
67 40 1036117659380117375
46 24 265457274847122243
63 44 438254608190938148
28 23 992625102587165494
57 87 558124114385470345
6 17 535...

output:

No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
...

result:

wrong answer expected YES, found NO [1st token]