CodeVs 2833 奇怪的梦境
2014-10-30 20:59
211 查看
思路 : 判断拓扑排序中是否有环,以及最终入度不为零的点有几个
从总数n中,每找到一个入度为零的点,n--,判断最终n的值即可。开始时候T了,竟然是因为边数组开小了。。。。为何不是RE啊!!!
AC代码
从总数n中,每找到一个入度为零的点,n--,判断最终n的值即可。开始时候T了,竟然是因为边数组开小了。。。。为何不是RE啊!!!
AC代码
#include<iostream> #include<string> #include<cstring> #include<cstdio> #include<cmath> #include<iomanip> #include<map> #include<queue> #include<set> #define pi acos(-1.0) #define eps 1e-8 typedef long long ll; using namespace std; const int maxn=10005; int in[maxn],vis[maxn],head[maxn],cnt,tot,n; queue <int > q; struct edge { int v,next; } E[3*maxn]; void init() { cnt=0; memset(vis,0,sizeof(vis)); memset(in,0,sizeof(in)); memset(head,-1,sizeof(head)); } void add_edge(int u,int v) { E[cnt].v=v; E[cnt].next=head[u]; head[u]=cnt++; } void toposort() { int i,j,k; for(i=1; i<=n; i++) if(in[i]==0) q.push(i),in[i]--; while(!q.empty()) { int j=q.front(); q.pop(); for(int k=head[j]; k!=-1; k=E[k].next) { int tmp=E[k].v; in[tmp]--; if(in[tmp]==0) q.push(tmp),in[tmp]--; } tot--; } } int main() { init(); int i,m,u,v; scanf("%d%d",&n,&m); for(i=0; i<m; i++) { scanf("%d%d",&u,&v); add_edge(u,v); in[v]++; } tot=n; toposort(); if(tot==0) printf("o(∩_∩)o\n"); else printf("T_T\n%d\n",tot); return 0; }
相关文章推荐
- 【codevs 2833】奇怪的梦境
- 【codevs 2833】奇怪的梦境
- Codevs 2833 奇怪的梦境
- codevs2833 奇怪的梦境 x
- 【CODEVS】2833 奇怪的梦境
- codevs 2833 奇怪的梦境 拓扑排序
- 【CODEVS】2833 奇怪的梦境
- codevs 2833 奇怪的梦境
- 【拓扑排序】CODEVS 2833 奇怪的梦境
- 2833 奇怪的梦境
- 2833 奇怪的梦境
- 2833 奇怪的梦境
- codevs 2833 奇怪的梦境 题解报告
- 奇怪的梦境(codevs 2833)
- Codevs 2833 奇怪的梦境
- codevs 2833 奇怪的梦境
- 【CS 2833】奇怪的梦境(拓扑排序top_sort)
- 2833 奇怪的梦境 【解题报告】
- 2833 奇怪的梦境
- CODEVS——T 2833 奇怪的梦境