题意:https://codeforces.com/contest/1715/problem/D
思路:首先对于k某位为0的话,那么i和j这一位上一定是0,所以我们考虑用a数组记录确定下来的位,a数组0的意义代表一定为0,1的意义代表可能0可能1,然后我们从头往后面贪心即可。
/*keep on going and never give up*/
#include<cstdio>
#include<iostream>
#include<queue>
#include<algorithm>
using namespace std;
#define int long long
typedef pair<int, int> pii;
#define lowbit(x) x&(-x)
#define endl '\n'
#define wk is zqx ta die
int a[100005];
int ans[100005];
vector<pii> pl[100005];
signed main() {std::ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);int n, q;cin >> n >> q;for (int i = 1; i <= n; i++) {a[i] = (1 << 30) - 1;}for (int i = 1; i <= q; i++) {int u, v, k;cin >> u >> v >> k;pl[u].push_back({v, k});pl[v].push_back({u, k});a[u] &= k;a[v] &= k;}for (int i = 1; i <= n; i++) {for (auto [j, val] : pl[i]) {if (j == i) {ans[i] = val;} else if (i < j) {for (int f = 0; f < 30; f++) {if (((a[j] >> f) & 1) == 0) {if ((val >> f) & 1) {ans[i] |= (1 << f);}}}} else {for (int f = 0; f < 30; f++) {if (((ans[j] >> f) & 1) == 0) {if ((val >> f) & 1) {ans[i] |= (1 << f);}}}}}}for (int i = 1; i <= n; i++) {cout << ans[i] << " ";}cout << endl;return 0;
}