HDU 4324 Triangle LOVE(拓扑排序)
2012-08-23 11:49
309 查看
题目链接
有结论。。在有向图中,每两个点都存在一条边,如果存在环,则一定存在3元环。拓扑排序一下。
有结论。。在有向图中,每两个点都存在一条边,如果存在环,则一定存在3元环。拓扑排序一下。
#include <stdio.h> #include <string.h> char str[2001][2001]; int o1[2001],o2[2001],k[2001]; int main() { int t,i,j,num = 0,n,z,nu; scanf("%d",&t); while(t--) { num ++; memset(k,0,sizeof(k)); memset(o1,0,sizeof(o1)); memset(o2,0,sizeof(o2)); scanf("%d%*c",&n); for(i = 0; i <= n-1; i ++) gets(str[i]); for(i = 0; i <= n-1; i ++) { for(j = 0; j <= n-1; j ++) { if(str[i][j] == '1') { o1[i] ++; o2[j] ++; } } } nu = 0; for(;;) { z = 0; for(i = 0; i <= n-1; i ++) { if(o2[i] == 0&&!k[i]) { k[i] = 1; z = 1; nu ++; for(j = 0;j <= n-1;j ++) { if(str[i][j] == '1'&&!k[j]) { o2[j] --; } } } } if(nu == n) break; if(!z) break; } if(nu == n) z = 0; else z = 1; printf("Case #%d: ",num); if(z) printf("Yes\n"); else printf("No\n"); } return 0; }
相关文章推荐
- HDU 4324 Triangle LOVE 【拓扑排序】
- hdu 4324 Triangle LOVE 拓扑排序
- HDU - 4324 Triangle LOVE(拓扑排序 + 判断环路)
- hdu 4324 Triangle LOVE(拓扑排序)
- HDU 4324-- Triangle LOVE【拓扑排序 && 邻接表实现】
- hdu 4324 Triangle LOVE 拓扑排序
- hdu 4324 Triangle LOVE(拓扑排序)
- HDU 4324 Triangle LOVE(拓扑排序)
- HDU-4324 Triangle LOVE 拓扑排序
- HDU 4324题Triangle LOVE(拓扑排序)
- hdu 4324 Triangle LOVE 拓扑排序
- HDU 4324 Triangle LOVE(拓扑排序)
- HDU 4324 Triangle LOVE (拓扑排序)
- HDU 4324 Triangle LOVE(拓扑排序)
- HDU 4324 Triangle LOVE 拓扑排序
- HDU 4324 Triangle LOVE (拓扑排序)
- hdu 4324 Triangle LOVE(拓扑排序)
- HDU 4324:Triangle LOVE( 拓扑排序 )
- HDU 4324 (拓扑排序) Triangle LOVE
- hdu 4324 Triangle LOVE(拓扑排序)