"Bzoj" "1529" "POI2005" Ska piggy Banks

Source: Internet
Author: User

I thought it was tarjan. However, 64MB space is not enough to save the original image and the new map after the indentation. So...... and check set = =

Orz Hzwer

Tarjan of MLE:

1 /**************************************************************2 problem:15293 User:tunix4 language:c++5 Result:memory_limit_exceed6 ****************************************************************/7  8 //Bzoj 15299#include <cstdio>Ten#include <cstring> One#include <cstdlib> A#include <iostream> -#include <algorithm> - #defineRep (i,n) for (int i=0;i<n;++i) the #defineF (i,j,n) for (int i=j;i<=n;++i) - #defineD (i,j,n) for (int i=j;i>=n;--i) - using namespacestd; - Const intn=1000086; +   - voidReadint&v) { +v=0;intsign=1;CharCh=GetChar (); A      while(ch<'0'|| Ch>'9') {if(ch=='-') sign=-1; Ch=GetChar ();} at      while(ch>='0'&&ch<='9') {v=v*Ten+ch-'0'; Ch=GetChar ();} -v*=Sign ; - } - /********************tamplate*******************/ - intDfn[n],low[n],dfs_clock,scc=0, Belong[n],n; - inthead[n],to[n],next[n],cnt; in voidInsintXinty) { -To[++cnt]=y; NEXT[CNT]=HEAD[X]; head[x]=CNT; to } + intT[n],ne[n],h[n]; - voidAddintXinty) { theT[++cnt]=y; NE[CNT]=H[X]; h[x]=CNT; * } $ BOOLInst[n];Panax Notoginseng intst[n],top=0; - voidTarjan (intx) { the     inty; +dfn[x]=low[x]=++Dfs_clock; Ast[top++]=x; theinst[x]=1; +      for(intI=head[x];i;i=Next[i]) { -y=To[i]; $         if(!Dfn[y]) { $ Tarjan (y); -low[x]=min (low[x],low[y]); -         } the         Else if(Inst[y]) low[x]=min (low[x],dfn[y]); -     }Wuyi     if(dfn[x]==Low[x]) { the++SCC; -          for(y=0; y!=x;) { Wuy=st[--top]; -inst[y]=0; Aboutbelong[y]=SCC; $         } -     } - } - int inch[N]; A voidrebuild () { +F (x,1, N) the          for(intI=head[x];i;i=Next[i]) -             if(belong[x]!=Belong[to[i]]) { $ Add (Belong[x],belong[to[i]]); the                 inch[belong[to[i]]]++; the             } the } the /***********************************************/ -   in intMain () { the #ifndef Online_judge theFreopen ("1529.in","R", stdin); About #endif the read (n); the     intx; theF (I,1, N) { + read (x); - ins (x,i); the     }BayiF (I,1, N)if(!Dfn[i]) Tarjan (i); the rebuild (); the     intans=0; -F (I,1, SCC)if(inch[i]==0) ans++; -printf"%d\n", ans); the     return 0; the}
View Code

And check the set:

1 /**************************************************************2 problem:15293 User:tunix4 language:c++5 result:accepted6 time:908 Ms7 memory:4712 KB8 ****************************************************************/9  Ten //Bzoj 1529 One#include <cstdio> A #defineRep (i,n) for (int i=0;i<n;++i) - #defineF (i,j,n) for (int i=j;i<=n;++i) - #defineD (i,j,n) for (int i=j;i>=n;--i) the using namespacestd; - Const intn=1000086; -   - voidReadint&v) { +v=0;intsign=1;CharCh=GetChar (); -      while(ch<'0'|| Ch>'9') {if(ch=='-') sign=-1; Ch=GetChar ();} +      while(ch>='0'&&ch<='9') {v=v*Ten+ch-'0'; Ch=GetChar ();} Av*=Sign ; at } - intFa[n],n; - intGetfather (intx) { -     if(fa[x]!=x) fa[x]=Getfather (fa[x]); -     returnFa[x]; - } in intMain () { - read (n); to     intx; +F (I,1, N) fa[i]=i; -F (I,1, N) { the read (x); *         intF1=getfather (i), f2=getfather (x); $         if(F1!=F2) fa[f1]=F2;Panax Notoginseng     } -     intcn1=0; theF (I,1, N)if(fa[i]==i) ans++; +printf"%d\n", ans); A     return 0; the}
View Code

"Bzoj" "1529" "POI2005" Ska piggy Banks

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.