心态崩了,有没有好心人?

P2746 [USACO5.3] 校园网Network of Schools

~~没有,下一个~~
by zhanghengrui @ 2019-03-16 22:54:09


@[zhanghengrui](/space/show?uid=110634) 巨老劳烦瞄两眼?
by Grussg @ 2019-03-17 08:38:04


改了没@[TheOrnateJade_ofSun](/space/show?uid=134876)
by Alpha丶 @ 2019-03-17 10:12:19


```c #include<bits/stdc++.h> using namespace std; const int G=9090; int dfn[G],low[G],vis[G],st[G],clo[G],head[G],in[G],out[G]; int tot,top,num,n,p,sum,coo; struct node{ int st,end,nxt; }e[G]; void add(int u,int v){ e[++tot].st=u; e[tot].end=v; e[tot].nxt=head[u]; head[u]=tot; } void tarjan(int u){ dfn[u]=low[u]=++num; //vis[u]=1; st[++top]=u; for(int i=head[u];i;i=e[i].nxt){ int v=e[i].end; if(!dfn[v]){ tarjan(v); low[u]=min(low[u],low[v]); } else if(!clo[v]) low[u]=min(low[u],dfn[v]); } if(low[u]==dfn[u]){ clo[u]=++coo; while(st[top]!=u){ clo[st[top]]=coo; top--; } top--; } } int main(){ memset(in,0,sizeof(in)); memset(out,0,sizeof(out)); cin>>n; for(int i=1;i<=n;i++){ cin>>p; while(p!=0){ add(i,p); cin>>p; } } for(int i=1;i<=n;i++){ if(!dfn[i])tarjan(i); } for(int u=n;u>=1;u--) for(int i=head[u];i;i=e[i].nxt){ int mb=e[i].end; if(clo[u]!=clo[mb]){ in[clo[mb]]++; out[clo[u]]++; } } int ans1=0;int ans2=0; for(int i=1;i<=coo;i++){ if(in[i]==0)ans1++; if(out[i]==0)ans2++; } if(coo==1) cout<<1<<endl<<0; else cout<<ans1<<endl<<max(ans1,ans2); return 0; } ``` 改完了
by Alpha丶 @ 2019-03-17 10:12:40


|