提交时间:2022-04-12 23:31:11
运行 ID: 48442
#include <bits/stdc++.h> using namespace std; const int N = 2e5 + 10, mod = 1e9 + 7; #define int long long int n, m, ttt; int ind[N]; #define mod(x, m) ((x) % (m) + (m)) % (m) void exgcd(int a, int b, int& x, int& y) { if (!b) x = 1, y = 0; else exgcd(b, a % b, y, x), y -= a / b * x; } int qny(int a, int p = mod) { int x, y; exgcd(a, p, x, y); x = mod(x, p); return x; } signed main() { scanf("%lld%lld%lld", &n, &m, &ttt); for (int x, y, i = 1; i <= m; i++) { scanf("%lld%lld", &x, &y); ind[y]++; } int ans = 1; for (int i = 1; i <= n; i++) { if (ind[i]) ans = mod(ans * ind[i], mod); } printf("%lld\n", ans); for (int x, y, i = 1; i <= ttt; i++) { scanf("%lld%lld", &x, &y); ans = mod(ans * qny(ind[y]), mod); ind[y]++; ans = mod(ans * ind[y], mod); printf("%lld\n", ans); } return 0; }