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 65 66 67
| #include <bits/stdc++.h> #define int long long #define re register using namespace std; typedef pair<int,int> pii; const int mod = 1000000007,inv = 500000004; int n,m,k,num,sum = 1,t = 1; map<int,int> mp; map<pii,bool> vis; inline int read(){ int r = 0,w = 1; char c = getchar(); while (c < '0' || c > '9'){ if (c == '-') w = -1; c = getchar(); } while (c >= '0' && c <= '9'){ r = (r << 3) + (r << 1) + (c ^ 48); c = getchar(); } return r * w; } inline int Add(int a,int b){ return (a + b) % mod; } inline int Sub(int a,int b){ return ((a - b) % mod + mod) % mod; } inline int Mul(int a,int b){ return a * b % mod; } inline int qmi(int a,int b){ int res = 1; while (b){ if (b & 1) res = Mul(res,a); a = Mul(a,a); b >>= 1; } return res; } signed main(){ n = read(); m = read(); k = read(); sum = Mul(Mul(Add(1,n),n),inv); for (re int i = 1;i <= k;i++){ int x,y; x = read(); y = read(); if (!mp.count(x)) num++; if (!vis.count({x,y})){ mp[x] = Add(mp[x],y); vis[{x,y}] = true; } } for (auto it = mp.begin();it != mp.end();it++) t = Mul(t,Sub(sum,it -> second)); printf("%lld",Mul(qmi(sum,m - num),t)); return 0; }
|