#include #include #include #include #include #include using namespace std; using lli = long long int; class rational{ public: rational(){x = 0, y = 1;} rational(lli a, lli b){x = a, y = b;} lli x, y; rational operator+(rational a){ rational r((x*a.y + a.x*y), y*a.y); lli g = gcd(r.x, r.y); r.x /= g, r.y /= g; if(r.y < 0) r.x = -r.x, r.y = -r.y; return r; } rational operator-(rational a){ rational r((x*a.y - a.x*y), y*a.y); lli g = gcd(r.x, r.y); r.x /= g, r.y /= g; if(r.y < 0) r.x = -r.x, r.y = -r.y; return r; } rational operator*(rational a){ rational r(x*a.x, y*a.y); lli g = gcd(r.x, r.y); r.x /= g, r.y /= g; if(r.y < 0) r.x = -r.x, r.y = -r.y; return r; } rational operator/(rational a){ if(a.x == 0){ cerr << "divided by zero." << endl; exit(1); } rational r(x*a.y, y*a.x); lli g = gcd(r.x, r.y); r.x /= g, r.y /= g; if(r.y < 0) r.x = -r.x, r.y = -r.y; return r; } }; mt19937 mt(234298343); // uniform_int_distribution rndgen(0, 49725516559); uniform_int_distribution rndgen(0, 1e9+7); int Rank(vector > M){ // for(int i = 0; i < M.size(); i++) { // for(int j = 0; j < M.size(); j++) { // cout << M[i][j].x << "/" << M[i][j].y << " "; // } // cout << endl; // } // cout << endl; // cout << endl; int pivot = -1, r = 0; rational z; for(int i = 0; i < M.size(); i++) { // cout << "i:" << i << ", pivot:" << pivot << ", n:" << M.size() << endl; for(int j = pivot + 1; j < M.size(); j++) { // cout << "j:" << j << endl; pivot = 1e9; if(M[i][j].x != 0)pivot = j; for(int k = i+1; k < M.size() and M[i][j].x == 0; k++) { // cout << "hoge:" << M[i][j].x << endl; // cout << "fuga:" << M[k][j].x << endl; if(M[i][j].x == 0 and M[k][j].x != 0){ swap(M[i], M[k]); // z = rational(M[i][j]); pivot = j; break; } } if(pivot == j) break; } if(pivot >= M.size() - 1) break; z = M[i][pivot]; // for(int i = 0; i < M.size(); i++) { // for(int j = 0; j < M.size(); j++) { // cout << M[i][j].x << "/" << M[i][j].y << " "; // } // cout << endl; // } // cout << "piv:" << pivot << ", i:" << i << ", n:" << M.size() << endl; // cout << "z:" << z.x << "/" << z.y << endl; for(int j = 0; j < M.size(); j++) M[i][j] = M[i][j] / z; for(int j = i+1; j < M.size(); j++) { rational w = M[j][pivot]; // cout << "wwww:" << w.x << "/" << w.y << endl; for(int k = 0; k < M.size(); k++) M[j][k] = M[j][k] - (w * M[i][k]); } // cout << endl; // cout << endl; } r = 1e9; for(int i = M.size() - 1; i >= 0 and r == 1e9; i--) { for(int j = 0; j < M.size() and r == 1e9; j++) { if(M[i][j].x != 0) r = i; } } // for(int i = 0; i < M.size(); i++) { // for(int j = 0; j < M.size(); j++) { // if(M[i][j].x != 0) cout << "1 "; // else cout << "0 "; // } // // for(int j = 0; j < M.size(); j++) { // // cout << M[i][j].x << "/" << M[i][j].y << " "; // // } // cout << endl; // } return r; } int main(){ int n, m; // lli mod = 49725516559; lli mod = 1e9+7; cin >> n >> m; vector > M(n, vector(n, 0)); for(int i = 0; i < m; i++) { int x = rndgen(mt); int u, v, w; cin >> u >> v >> w; u--, v--, w--; M[u][v] = (M[u][v] + x)%mod; M[v][w] = (M[v][w] + x)%mod; M[w][u] = (M[w][u] + x)%mod; M[v][u] = (M[v][u] - x + mod)%mod; M[w][v] = (M[w][v] - x + mod)%mod; M[u][w] = (M[u][w] - x + mod)%mod; } vector > ratM(n, vector(n)); for(int i = 0; i < n; i++) { for(int j = 0; j < n; j++) { ratM[i][j] = rational(M[i][j], 1); } } int ans = 0; for(int i = 0; i < 10; i++) ans = max(ans, Rank(ratM)); // for(int i = 0; i < n; i++) { // for(int j = 0; j < n; j++) { // ratM[i][j] = rational(1, 1); // } // } // Rank(ratM); cout << ans/2 << endl; }