Advertisement
Guest User

Untitled

a guest
Nov 4th, 2024
32
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.59 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2.  
  3. using namespace std;
  4.  
  5. #define x first
  6. #define y second
  7. #define mp make_pair
  8. #define pb push_back
  9. #define sqr(a) ((a) * (a))
  10. #define sz(a) int(a.size())
  11. #define all(a) a.begin(), a.end()
  12. #define forn(i, n) for(int i = 0; i < int(n); i++)
  13. #define fore(i, l, r) for(int i = int(l); i < int(r); i++)
  14.  
  15. typedef long long li;
  16. typedef long double ld;
  17. typedef pair<int, int> pt;
  18.  
  19. template <class A, class B> ostream& operator << (ostream& out, const pair<A, B> &a) {
  20.     return out << "(" << a.x << ", " << a.y << ")";
  21. }
  22.  
  23. template <class A> ostream& operator << (ostream& out, const vector<A> &v) {
  24.     out << "[";
  25.     forn(i, sz(v)) {
  26.         if(i) out << ", ";
  27.         out << v[i];
  28.     }
  29.     return out << "]";
  30. }
  31.  
  32. mt19937 rnd(time(NULL));
  33.  
  34. const int INF = int(1e9);
  35. const li INF64 = li(1e18);
  36. const int MOD = int(1e9) + 7;
  37. const ld EPS = 1e-9;
  38. const ld PI = acos(-1.0);
  39.  
  40. struct query{
  41.     int v, k;
  42. };
  43.  
  44. int n, m, t;
  45. vector<vector<int>> g;
  46. vector<query> q;
  47.  
  48. bool read () {
  49.     if (!(cin >> n >> m >> t))
  50.         return false;
  51.     g.assign(n, {});
  52.     forn(i, m){
  53.         int v, u;
  54.         cin >> v >> u;
  55.         --v, --u;
  56.         g[v].pb(u);
  57.         g[u].pb(v);
  58.     }
  59.     q.resize(t);
  60.     forn(i, t){
  61.         cin >> q[i].v >> q[i].k;
  62.         --q[i].v;
  63.     }
  64.     return true;
  65. }
  66.  
  67. int add(int a, int b){
  68.     a += b;
  69.     if (a >= MOD)
  70.         a -= MOD;
  71.     return a;
  72. }
  73.  
  74. int mul(int a, int b){
  75.     return a * li(b) % MOD;
  76. }
  77.  
  78. int binpow(int a, int b){
  79.     int res = 1;
  80.     while (b){
  81.         if (b & 1)
  82.             res = mul(res, a);
  83.         a = mul(a, a);
  84.         b >>= 1;
  85.     }
  86.     return res;
  87. }
  88.  
  89. const int N = 203;
  90.  
  91. typedef array<array<int, N>, N> mat;
  92.  
  93. mat operator *(const mat &a, const mat &b){
  94.     mat c;
  95.     forn(i, N) forn(j, N) c[i][j] = 0;
  96.     forn(i, N) forn(j, N) forn(k, N) c[i][j] = add(c[i][j], mul(a[i][k], b[k][j]));
  97.     return c;
  98. }
  99.  
  100. void solve() {
  101.     vector<mat> sv(25);
  102.     forn(i, N) forn(j, N) sv[0][i][j] = 0;
  103.     forn(v, n) for (int u : g[v]) ++sv[0][v][u];
  104.     forn(i, sz(sv) - 1) sv[i + 1] = sv[i] * sv[i];
  105.     forn(z, t){
  106.         int v = q[z].v, k = q[z].k;
  107.         array<int, N> cur, nw;
  108.         forn(i, N) cur[i] = i < n;
  109.         forn(b, 25) if ((k >> b) & 1){
  110.             forn(i, N) nw[i] = 0;
  111.             forn(i, N) forn(j, N)
  112.                 nw[j] = add(nw[j], mul(cur[i], sv[b][i][j]));
  113.             cur = nw;
  114.         }
  115.         cout << cur[v] << '\n';
  116.     }
  117. }
  118.  
  119. int main() {
  120. #ifdef _DEBUG
  121.     freopen("input.txt", "r", stdin);
  122. //  freopen("output.txt", "w", stdout);
  123.    
  124.     int tt = clock();
  125. #endif
  126.    
  127.     cerr.precision(15);
  128.     cout.precision(15);
  129.     cerr << fixed;
  130.     cout << fixed;
  131.  
  132. #ifdef _DEBUG
  133.     while(read()) {
  134. #else
  135.     if(read()) {
  136. #endif
  137.         solve();
  138.        
  139. #ifdef _DEBUG
  140.     cerr << "TIME = " << clock() - tt << endl;
  141.     tt = clock();
  142. #endif
  143.  
  144.     }
  145. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement