Блог пользователя t3rminated

Автор t3rminated, 9 лет назад, По-английски

I was solving this its problem on perfect matching in a graph.I have to tell whether a graph can be perfect matched.I used tutte matrix and Gaussian elimination method to find whether a perfect matching exists but i don't know why my code doesn't works , please help!


#include "bits/stdc++.h" using namespace std; #define ll long long #define mod 10000+7 #define MAX 101 ll r,i,j,k; ll lcm(ll x,ll y) { ll t; while (y != 0) { t=y; y=x%y; x=t; } return x; } ll random_number_generator() { // Declare variable to hold seconds on clock. time_t seconds; // Get value from system clock and // place in seconds variable. time(&seconds); // Convert seconds to a unsigned // integer. srand((unsigned ll) seconds); // Output random values. return (rand()+mod) % mod; } ll det(ll a[101][101]) /*this code converts mtrix to upper triangle so dterminant can be found by taking product of just diagonal elements*/ {ll l,d1,d2; for(i=0;i<r-1;i++) { for(j=i+1;j<r;j++) { l=lcm(a[i][i],a[j][i]); if(l!=0&&(a[i][i]!=0&&a[j][i]!=0)) { l=(a[i][i]*a[j][i])/l; d1=l/a[i][i]; d2=l/a[j][i]; a[j][i]=0; for(k=i+1;k<r;k++) { a[j][k]=(d2*a[j][k])-(d1*a[i][k]); } } } } ll p =1; for(int i = 0 ;i < r; i++) { p = (p * a[i][i]+mod)%mod; p = (p * a[i][r-1-i] + mod)%mod; } return p; } int main(int argc, char const *argv[]) { ll t; cin >> t; while(t--) { ll n , m; cin >> n >> m; r=n; ll a[101][101]; for(ll i = 0; i <= n; i++) { for(ll j = 0; j <= n; j++) a[i][j] = 0; } ll rnd = random_number_generator(); while(m--) { ll x , y; cin >> x >> y; x--;y--; ll rnd = random_number_generator(); if(x < y) a[x][y] = (rnd); else if(x > y) a[x][y] = (-rnd); a[y][x] = -a[x][y]; } ll dete = det(a); if(dete == 0) cout << "NO" << endl; else cout << "YES" << endl; } return 0; }
  • Проголосовать: нравится
  • 0
  • Проголосовать: не нравится