Advertisement
Guest User

Untitled

a guest
Aug 22nd, 2019
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.93 KB | None | 0 0
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3.  
  4.  
  5. template <int mod>
  6. struct ModInt {
  7. int val;
  8. int trim(int x) const { return x >= mod ? x - mod : x < 0 ? x + mod : x; }
  9. ModInt(int v = 0) : val(trim(v % mod)) {}
  10. ModInt(long long v) : val(trim(v % mod)) {}
  11. ModInt &operator=(int v) { return val = trim(v % mod), *this; }
  12. ModInt &operator=(const ModInt &oth) { return val = oth.val, *this; }
  13. ModInt operator+(const ModInt &oth) const { return trim(val + oth.val); }
  14. ModInt operator-(const ModInt &oth) const { return trim(val - oth.val); }
  15. ModInt operator*(const ModInt &oth) const {
  16. return 1LL * val * oth.val % mod;
  17. }
  18. ModInt operator/(const ModInt &oth) const {
  19. function<int(int, int, int, int)> modinv = [&](int a, int b, int x, int y) {
  20. if (b == 0) return trim(x);
  21. return modinv(b, a - a / b * b, y, x - a / b * y);
  22. };
  23. return *this * modinv(oth.val, mod, 1, 0);
  24. }
  25. bool operator==(const ModInt &oth) const { return val == oth.val; }
  26. ModInt operator-() const { return trim(mod - val); }
  27. template<typename T> ModInt pow(T pw) {
  28. bool sgn = false;
  29. if (pw < 0) pw = -pw, sgn = true;
  30. ModInt ans = 1;
  31. for (ModInt cur = val; pw; pw >>= 1, cur = cur * cur) {
  32. if (pw&1) ans = ans * cur;
  33. }
  34. return sgn ? ModInt(1) / ans : ans;
  35. }
  36. };
  37.  
  38. template<typename T>
  39. vector<T> operator-(vector<T> A, vector<T> B) {
  40. for (int i = 0; i < A.size(); ++i) A[i] = A[i] - B[i];
  41. return A;
  42. }
  43.  
  44. template<typename T>
  45. vector<T> operator*(vector<T> A, T mul) {
  46. for (int i = 0; i < A.size(); ++i) A[i] = A[i] * mul;
  47. return A;
  48. }
  49.  
  50. template<typename T>
  51. vector<T> operator/(vector<T> A, T mul) {
  52. for (int i = 0; i < A.size(); ++i) A[i] = A[i] / mul;
  53. return A;
  54. }
  55.  
  56.  
  57. template<typename T>
  58. T det(vector<vector<T>> A) {
  59. int N = A.size();
  60. T ans{1};
  61. for (int r = 0; r < N; ++r) {
  62. if (A[r][r] == T{0}) return T{0};
  63. ans = ans * A[r][r];
  64. for (int pvt = r + 1; pvt < N; ++pvt) {
  65. A[pvt] = A[pvt] - A[r] * A[pvt][r] / A[r][r];
  66. }
  67. }
  68. return ans;
  69. }
  70.  
  71. const int MOD = 998244353;
  72.  
  73.  
  74. int main() {
  75. ios_base::sync_with_stdio(false); cin.tie(0);
  76. int T; cin >> T;
  77.  
  78. while (T--) {
  79. int n, m; long long k; cin >> n >> m >> k;
  80. int adj[50][50];
  81. for (int i = 0; i < n; ++i) for (int j = 0; j < n; ++j) {
  82. adj[i][j] = i == j ? n - 1 : -1;
  83. }
  84. while (m--) {
  85. int u, v; cin >> u >> v;
  86. --u, --v;
  87. adj[u][v] = adj[v][u] = 0;
  88. --adj[u][u], --adj[v][v];
  89. }
  90. vector<vector<ModInt<MOD>>> mtx;
  91. if (k == 1) {
  92. mtx.assign(n - 1, vector<ModInt<MOD>>(n - 1));
  93. for (int i = 0; i < n - 1; ++i) for (int j = 0; j < n - 1; ++j) {
  94. mtx[i][j] = adj[i][j];
  95. }
  96. cout << det(mtx).val << '\n';
  97. }
  98. else {
  99. mtx.assign(n, vector<ModInt<MOD>>(n));
  100. for (int i = 0; i < n; ++i) for (int j = 0; j < n; ++j) {
  101. mtx[i][j] = adj[i][j] + (i == j ? (k - 1) * n % MOD : 0);
  102. }
  103. cout << ((det(mtx)/ModInt<MOD>{(k - 1) * n % MOD}).pow(k) *
  104. ModInt<MOD>(1ll * n * k % MOD).pow(k - 2)).val << '\n';
  105. }
  106. }
  107.  
  108. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement