SHARE
TWEET

Untitled

a guest Aug 25th, 2019 63 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <iostream>
  2. #include <fstream>
  3. #include <cmath>
  4. using namespace std;
  5. ifstream f("arbori_in_graf.in");
  6. ofstream g("arbori_in_graf.out");
  7. const double EPS = 1E-9;
  8. double a[51][51],det;
  9. int n,m,x,y,grad[51],i,j,k;
  10. int main()
  11. {
  12.     f>>n>>m;
  13.     while(m--)
  14.     {
  15.         f>>x>>y;
  16.         x--;
  17.         y--;
  18.         a[x][y]--;
  19.         a[y][x]--;
  20.         grad[x]++;
  21.         grad[y]++;
  22.     }
  23.     for(i=0;i<n;i++)
  24.     {
  25.         a[i][i]=grad[i];
  26.     }
  27.     n--;
  28.     det = 1;
  29.     for (i=0; i<n; ++i) {
  30.     k = i;
  31.     for (j=i+1; j<n; ++j)
  32.         if (abs (a[j][i]) > abs (a[k][i]))
  33.             k = j;
  34.     if (abs (a[k][i]) < EPS) {
  35.         det = 0;
  36.         break;
  37.     }
  38.     swap (a[i], a[k]);
  39.     if (i != k)
  40.         det = -det;
  41.     det *= a[i][i];
  42.     for (int j=i+1; j<n; ++j)
  43.         a[i][j] /= a[i][i];
  44.     for (j=0; j<n; ++j)
  45.         if (j != i && abs (a[j][i]) > EPS)
  46.             for (k=i+1; k<n; ++k)
  47.                 a[j][k] -= a[i][k] * a[j][i];
  48.     }
  49.     g << det;
  50.     return 0;
  51. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top