标签:problems accept namespace for efi int 答案 blog 一个
Time Limit: 10000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 3937 Accepted Submission(s): 1775
#include<iostream> #include<cstdio> #include<cstring> #include<algorithm> #define MAXN 100000+15 using namespace std; int n,m,tot,tim,top,sumcol,ans,bns,val[MAXN]; int to[MAXN],from[MAXN],net[MAXN],x[MAXN],col[MAXN],into[MAXN],out[MAXN]; int dfn[MAXN],low[MAXN],vis[MAXN],stack[MAXN],visstack[MAXN]; inline void add(int u,int v){ to[++tot]=v;x[tot]=u;net[tot]=from[u];from[u]=tot; } inline void tarjin(int now){ low[now]=dfn[now]=++tim; stack[++top]=now; visstack[now]=1; vis[now]=1; for(int i=from[now];i;i=net[i]) if(visstack[to[i]]) low[now]=min(low[now],dfn[to[i]]); else if(!vis[to[i]]){ tarjin(to[i]); low[now]=min(low[now],low[to[i]]); } if(dfn[now]==low[now]){ sumcol++; col[now]=sumcol; while(stack[top]!=now){ col[stack[top]]=sumcol; visstack[stack[top]]=0; top--; } visstack[now]=0; top--; } } int main(){ while(scanf("%d%d",&n,&m)!=EOF){ top=0;tot=0;sumcol=0;tim=0; ans=0;bns=0; memset(to,0,sizeof(to)); memset(low,0,sizeof(low)); memset(dfn,0,sizeof(dfn)); memset(vis,0,sizeof(vis)); memset(col,0,sizeof(col)); memset(net,0,sizeof(net)); memset(out,0,sizeof(out)); memset(into,0,sizeof(into)); memset(from,0,sizeof(from)); memset(stack,0,sizeof(stack)); memset(visstack,0,sizeof(visstack)); for(int i=1;i<=n;i++) scanf("%d",&val[i]); for(int i=1;i<=m;i++){ int a,b; scanf("%d%d",&a,&b); add(a,b); } for(int i=1;i<=n;i++) if(!vis[i]) tarjin(i); for(int i=1;i<=m;i++) if(col[to[i]]!=col[x[i]]){ into[col[to[i]]]++; out[col[x[i]]]++; } for(int i=1;i<=sumcol;i++){ if(into[i]==0){ ans++; int minn=0x7f7f7f7f; for(int j=1;j<=n;j++) if(col[j]==i) minn=min(minn,val[j]); bns+=minn; } } printf("%d %d\n",ans,bns); } }
标签:problems accept namespace for efi int 答案 blog 一个
原文地址:http://www.cnblogs.com/cangT-Tlan/p/7400490.html