Hdu 5154 Harry and magical computer

Source: Internet
Author: User

http://acm.hdu.edu.cn/showproblem.php?pid=5154

Idea: There is a direction to figure out whether there is a ring, can be used Floyd.

1#include <cstdio>2#include <cstring>3#include <algorithm>4 using namespacestd;5 Const intinf=1<< -;6 7 intg[ $][ $];8 intMain ()9 {Ten     intn,m; One      while(SCANF ("%d%d", &n,&m)! =EOF) A     { -Memset (G,0,sizeof(g)); -          for(intI=1; i<=n; i++) the         { -              for(intj=1; j<=n; J + +) -             { -g[i][j]=inf; +             } -         } +          for(intI=0; i<m; i++) A         { at             intb; -scanf"%d%d",&a,&b); -g[b][a]=1; -         } -          for(intk=1; k<=n; k++) -         { in              for(intI=1; i<=n; i++) -             { to                  for(intj=1; j<=n; J + +) +                 { -                     if(i==k| | J==K)Continue; theG[i][j]=min (g[i][j],g[i][k]+g[k][j]); *                 } $             }Panax Notoginseng         } -         BOOLflag=true; the          for(intI=1; i<=n; i++) +         { A             if(g[i][i]<inf) the             { +flag=false; -                  Break; $             } $         } -         if(flag) printf ("yes\n"); -         Elseprintf"no\n"); the     } -     return 0;Wuyi}
View Code

Hdu 5154 Harry and magical computer

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.