description:
题意有点难读 具体化的讲就是有n个点,每个点有点权。用这n个点来构造q个无向图,对于每个无向图Ei来说
规定属于Ei的点x,y. 满足Valx ^ Valy = k 就会有一条权值为1的边,问点x到点y的最短距离
solution:
首先是异或的一个性质 a ^ b = c <-> a ^ c = b <-> b ^ c = a 这三个是等价的
1.当a[x] ^ a[y] == k 时 他们之间有条边 输出1即可
2.当a[x] == a[y] 的时候 通过一个中间点来到达 即 k ^ c 判断是否存在 走了2步
3. 无法到达
code:
#include <bits/stdc++.h> using namespace std; #define LL long long #define ULL unsigned long long #define mes(x, a) memset(x, a, sizeof(x)); #define sca(a) scanf("%d", &a) #define lowbit(x) x &(-x) #define mk make_pair #define pb(x) push_back(x) #define all(x) (x).begin(), (x).end() #define fi first #define se second #define lson v << 1 #define rson v << 1 | 1 #define pii pair<int, int> inline void read(int &x) { x = 0; int flag_read = 1; char c = getchar(); while (c < '0' || c > '9') { if (c == '-') flag_read = -1; c = getchar(); } while (c >= '0' && c <= '9') { x = (x << 3) + (x << 1) + c - '0'; c = getchar(); } x *= flag_read; } void out(int x) { if (x > 9) { out(x / 10); } putchar(x % 10 + '0'); } const int N = 1e7 + 50; int a[N]; int vis[N]; int main() { int n, q; scanf("%d%d",&n,&q); for (int i = 1; i <= n; i++) { scanf("%d",&a[i]); vis[a[i]] = 1; } while (q--) { int k, x, y; scanf("%d%d%d",&k,&x,&y); x = a[x], y = a[y]; if ((x ^ y) == k) { puts("1"); } else if (x == y && vis[k ^ x]) { puts("2"); } else { puts("-1"); } } return 0; }