bzoj 2208: [Jsoi2010]連通數

來源:互聯網
上載者:User

標籤:

一看就是縮點拓撲啊,可資料範圍這麼小,暴力即可啊。

 1 #include<cstdio> 2 #include<iostream> 3 #include<cstring> 4 #include<cstdlib> 5 #include<cmath> 6 #include<queue> 7 #include<algorithm> 8 #include<vector> 9 #define M 100000910 #define EPS 1e-1011 #define MO 1965082712 #define ll long long13 using namespace std;14 ll read()15 {16     char ch=getchar();17     ll x=0,f=1;18     for(;ch<‘0‘||ch>‘9‘;ch=getchar())19         if(ch==‘-‘)20           f=-1;21     for(;ch>=‘0‘&&ch<=‘9‘;ch=getchar())22         x=x*10+ch-‘0‘;23     return x*f;24 }25 int f[M],ans,cnt,n,head[M],next[M],u[M];26 char ch[M];27 void jia(int a1,int a2)28 {29   cnt++;30   next[cnt]=head[a1];31   head[a1]=cnt;32   u[cnt]=a2;33 }34 void dfs(int x,int y)35 {36   f[y]=x;37   ans++;38   for(int i=head[y];i;i=next[i])39     if(f[u[i]]<x)40       dfs(x,u[i]);41 }42 int main()43 {44    n=read();45    for(int i=1;i<=n;i++)46      {47        scanf("%s",ch+1);48        for(int j=1;j<=n;j++)49          if(ch[j]==‘1‘)50            jia(i,j);51      }52    for(int i=1;i<=n;i++)53      dfs(i,i);54    printf("%d\n",ans);55    return 0;56 }57 

 

bzoj 2208: [Jsoi2010]連通數

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.