码迷,mamicode.com
首页 > 其他好文 > 详细

SP104 HIGH - Highways

时间:2019-01-13 23:25:51      阅读:220      评论:0      收藏:0      [点我收藏+]

标签:include   swa   names   sizeof   mem   tchar   i+1   complete   clu   

题目

SP104 HIGH - Highways

做法

luogu上直接swap会CE

度数矩阵-邻接矩阵任意去掉一行\(i\)和一列\(i\)然后求解行列式,取单位矩矩阵乘积

裸的矩阵树啊

My complete code

#include<cstdio>
#include<cstring>
#include<algorithm>
#include<iostream>
#include<string>
using namespace std;
typedef long long LL;
const int maxn=1e3+9;
const double eps=1e-7;
inline LL Read(){
    LL x(0),f=1; char c=getchar();
    while(c<'0'||c>'9'){
        if(c=='-')f=-1; c=getchar();
    }
    while(c>='0'&&c<='9')
        x=(x<<3)+(x<<1)+c-'0',c=getchar();
    return x*f;
}
LL n,m,T;
double D[maxn][maxn];
inline void Solve(){
    --n;
    for(LL i=1;i<=n;++i){
        LL mx=i;
        for(LL j=i+1;j<=n;++j)
            if(D[j][i]>D[mx][i])
                mx=j;
        if(D[mx][i]<eps&&D[mx][i]>-eps){
            printf("0\n");
            return;
        }
        if(mx!=i){
            for(LL j=1;j<=n;++j){
                LL c(D[i][j]);
                D[i][j]=D[mx][j],D[mx][j]=c;
            }
        }
        for(LL j=i+1;j<=n;++j){
            double tmp=D[j][i]/D[i][i];
            for(LL k=i;k<=n;++k)
                D[j][k]-=tmp*D[i][k];
        }
    }
    double ans=1.0;
    for(LL i=1;i<=n;++i)
        ans*=D[i][i];
    printf("%0.f\n",ans);
}
int main(){
    T=Read();
    while(T--){
        n=Read(),m=Read();
        memset(D,0,sizeof(D));
        while(m--){
            LL u(Read()),v(Read());
            ++D[u][u],++D[v][v],
            --D[u][v],--D[v][u];
        }
        Solve();
    }
    return 0;
}

SP104 HIGH - Highways

标签:include   swa   names   sizeof   mem   tchar   i+1   complete   clu   

原文地址:https://www.cnblogs.com/y2823774827y/p/10264412.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!