hdu 4324 Triangle LOVE 拓扑排序 多校联合赛(三)第四题
2012-08-01 19:35
204 查看
拓扑排序,如果中间遇见环了就NO啦!if A don’t love B, then B must love A,说明两点之间必有连线,而且And there is no possibility that
two people love each other, what a crazy world!所以只要遇见环,一定能换成三角关系
two people love each other, what a crazy world!所以只要遇见环,一定能换成三角关系
#include<iostream> #include<cstdio> using namespace std; #define N 2010 int indegree ,a ; char b ; int main(){ // freopen("in.txt","r",stdin); int n,t,x,p=1; scanf("%d",&t); while(t--){ int sign1=0; scanf("%d",&n); for(int i=0;i<=n;i++){ indegree[i]=0; } for(int i=1;i<=n;i++){ scanf("%s",b); for(int j=0;j<n;j++){ a[i][j+1]=b[j]-'0'; if(a[i][j+1]==1) indegree[j+1]++;//入度数组 } } printf("Case #%d: ",p++); for(int i=1;i<=n;i++){ int temp; int sign=0; for(int j=1;j<=n;j++){ if(indegree[j]==0){ temp=j; indegree[j]=-1; sign=1; break; } } if(sign==0){//如果没有找到定点,那一定有环了 printf("Yes\n"); sign1=1; break; } else{ for(int j=1;j<=n;j++){ if(a[temp][j]&&temp!=j) indegree[j]--; } } } if(sign1==0){ printf("No\n"); } } return 0; }
相关文章推荐
- HDU 4324 Triangle LOVE 【拓扑排序】
- HDU 4324 CODE[VS] 2066 triangle love(拓扑排序)
- [HDU 4324] Triangle LOVE (拓扑排序,DFS)
- 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 4323 Magic Number dp 多校联合赛(三)第四题
- HDU 4324 Triangle LOVE 拓扑排序
- hdu 4324 Triangle LOVE(拓扑排序)
- HDU 4324:Triangle LOVE( 拓扑排序 )
- HDU 4324-- Triangle LOVE【拓扑排序 && 邻接表实现】
- HDU 4324题Triangle LOVE(拓扑排序)
- HDU 4324 Triangle LOVE(拓扑排序)