SPOJ 106 Highways (minimum spanning tree count)

Source: Internet
Author: User

Title Link: http://www.spoj.pl/problems/HIGH/

Test instructions: The minimum number of spanning trees is obtained.

1#include <algorithm>2#include <cstdio>3#include <cmath>4#include <cstring>5#include <iostream>6 #definell Long Long7 Doublea[205][205];8 intn,m;9 Const Doubleeps=1e- the;Ten intZeroDoublex) { One     if(x<-eps)return-1; A     Else returnX>EPS; - } - DoubleWork () { the     Doubleres=1; -      for(intI=1; i<=n;i++){ -         intk=i; -          for(intj=i+1; j<=n;j++)if(Fabs (A[j][i]) >fabs (A[k][i]) k=J; +         if(k!=i) { -              for(intj=1; j<=n;j++) + Std::swap (A[k][j],a[i][j]); A         } at          for(intj=i+1; j<=n;j++){ -             Doubletmp=a[j][i]/A[i][i]; -              for(intk=i;k<=n;k++) -a[j][k]-=tmp*A[i][k]; -         } -         if(!zero (A[i][i]))return 0; in     } -      for(intI=1; i<=n;i++) res*=A[i][i]; to     returnStd::fabs (res); + } - intMain () { the     intT; *scanf"%d",&T); $      while(t--){Panax Notoginsengscanf"%d%d",&n,&m); -          for(intI=0; i<=n;i++) the           for(intj=0; j<=n;j++) +a[i][j]=0; A          while(m--){ the             intx, y; +scanf"%d%d",&x,&y); -a[x][x]+=1.0; a[y][y]+=1.0; $a[x][y]-=1.0; a[y][x]-=1.0; $         }   -n--; -printf"%0.0lf\n", work ()); the     } -}

SPOJ 106 Highways (minimum spanning tree count)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.