2015 questions in group B in 9th, group B in 2015
// 10e9 can only be a Matrix Recursion !!!! // Matrix Recursion + binary power # include <iostream> # include <cstdio> # include <cstdlib> # include <cstring> # include <vector> # include <algorithm> # include <cmath> using namespace std; typedef long LL; const int Mod = 1000000007; struct Matrix {LL a [6] [6]; Matrix (int x) {memset (a, 0, sizeof (a); for (int I = 0; I <6; I ++) a [I] [I] = x ;} matrix operator * (const Matrix & B) const {Matrix c (0); for (int I = 0; I <6; I ++) for (int j = 0; j <6; j ++) for (int k = 0; k <6; k ++) {c. a [I] [j] + = (a [I] [k] * B. a [k] [j]) % Mod; c. a [I] [j] % = Mod;} return c ;}}; Matrix fast_mod (Matrix x, int r) {Matrix ret (1); while (r) {if (r & 1) ret = ret * x; x = x * x; r >>= 1;} return ret;} int main () {Matrix st (0); for (int I = 0; I <6; I ++) for (int j = 0; j <6; j ++) st. a [I] [j] = 4; int n, m; cin> n> m; for (int I = 0; I <m; I ++) {int u, v; cin> u> v; st. a [U-1] [V-1] = 0; st. a [V-1] [U-1] = 0;} Matrix ret = fast_mod (st, n-1); LL ans = 0; for (int I = 0; I <6; I ++) for (int j = 0; j <6; j ++) {ans + = (4 * ret. a [I] [j]) % Mod; ans % = Mod;} cout <ans <endl; return 0 ;}