-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path757c.cpp
64 lines (47 loc) · 1019 Bytes
/
757c.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pi = pair<ll, ll>;
using vi = vector<ll>;
using vpi = vector<pi>;
using vb = vector<bool>;
const ll mod = 1e9 + 7;
ll binpow(ll x, ll n, ll m) {
assert(n >= 0);
x %= m; // note: m * m must be less than 2^63 to avoid ll overflow
ll res = 1;
while (n > 0) {
if (n % 2 == 1) // if n is odd
res = res * x % m;
x = x * x % m;
n /= 2; // divide by two
}
return res;
}
void solve() {
ll n, m;
cin >> n >> m;
ll orsum = 0;
for (ll i = 0; i < m; i++) {
ll x, y, a;
cin >> x >> y >> a;
orsum |= a;
}
ll ans = 0;
ll i = 0;
while (orsum > 0) {
if (orsum & 1) ans += binpow(2, n - 1 + i, mod);
ans %= mod;
orsum >>= 1;
i++;
}
cout << ans << endl;
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
ll t;
cin >> t;
while(t--) solve();
return 0;
}