[Gaussian elimination binary graph maximum matching] [HEOI2013] BZOJ3168 Calcium Iron Zinc Selenium Vitamin __ Gauss elimination

Source: Internet
Author: User
Tags abs pow

Solving

#include <bits/stdc++.h> using namespace std;
const int n=310;
const int p=1000000007;
int k,n,m;
int a[n][n],b[n][n],inv[n][n],c[n][n];
int f[n],cur,v[n],t[n];
vector<int>g[n];
    int Abs (int x) {return x>0?x:-x;} int Pow (int x,int y) {int ans=1;
    for (; y;y>>=1,x=1ll*x*x%p) if (y&1) ans=1ll*ans*x%p;
return Ans;
    } void Get_inv () {for (int i=1;i<=n;i++) inv[i][i]=1;
        for (int i=1;i<=n;i++) {int pos=i;
        for (int j=i;j<=n;j++) if (Abs (A[j][i]) >abs (a[pos][i)) pos=j;
        for (int j=1;j<=n;j++) swap (a[i][j],a[pos][j]), swap (inv[i][j],inv[pos][j]);
        int T=pow (A[I][I],P-2);
        for (int j=1;j<=n;j++) a[i][j]=1ll*a[i][j]*t%p,inv[i][j]=1ll*inv[i][j]*t%p;
                for (int j=1;j<=n;j++) if (I!=j&&a[j][i]) {int x=a[j][i];
                    for (int k=1;k<=n;k++) {a[j][k]= (a[j][k]-1ll*x*a[i][k])%P; Inv[j][k]= (inv[j][k]-1ll*x*inV[I][K])%P;
    BOOL Dfs (int x) {if (v[x]==cur) return 0;
    V[x]=cur;
        for (int i=0;i<g[x].size (); i++) {int v=g[x][i]; if (!f[v]| |
            Dfs (F[v])) {f[v]=x;t[x]=v;
        return 1;
} return 0;
    BOOL Find (int x) {if (v[x]==cur) return 0;
    V[x]=cur;
        for (int i=0;i<g[x].size (); i++) {int v=g[x][i]; if (!f[v]| | (F[v]>cur&&find (F[v]))
            {f[v]=x;t[x]=v;
        return 1;
} return 0;
    int main () {scanf ("%d", &n);
    for (int i=1;i<=n;i++) for (int j=1;j<=n;j++) scanf ("%d", &a[i][j]);
    for (int i=1;i<=n;i++) for (int j=1;j<=n;j++) scanf ("%d", &b[i][j]);
    GET_INV (); for (int k=1;k<=n;k++) for (int i=1;i<=n;i++) for (int j=1;j<=n;j++) c[i][j]= (c[
    I][J]+1LL*B[I][K]*INV[K][J])%P;
    for (int i=1;i<=n;i++) for (int j=1;j<=n;j++)        if (C[i][j]) g[j].push_back (i);
        for (int i=1;i<=n;i++) {cur=i; if (!
            Dfs (i)) {puts ("NIE");
        return 0;
    } memset (V,0,sizeof (v));
    for (int i=1;i<=n;i++) cur=i,f[t[i]]=0,find (i);
    Puts ("TAK");
    for (int i=1;i<=n;i++) printf ("%d\n", T[i]);
return 0; }

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.