NOJ1119 Fairy Linding Amusement Park

Source: Internet
Author: User

Test instructions

Given an anisotropic graph, ask if there is a ring in the graph.

Ideas

Pretreatment is done in the form of Floyd. EG[I][J] Not only indicates that there is an edge attached to I and J, but a path I to J.
This process then iterates through all the circumstances, if found to be positive and opposite, that is the existence of the ring.

Code
#include <cstdio>Const intMAXN = -;intNBOOLEG[MAXN][MAXN];intMain () {//freopen ("In.txt", "R", stdin);    intTscanf("%d", &t); while(t--) { for(inti =0; i < MAXN; i + +) { for(intj =0; J < Maxn; J + +) Eg[i][j] =false; }intCscanf("%d%d", &n,&c); while(c--) {intb;scanf("%d%d", &a,&b); EG[A][B] =true; } for(intK =0; K < n; K + +) { for(inti =0; I < n; i + +) { for(intj =0; J < N; J + +) {if(Eg[k][i] && eg[i][j]) eg[k][j] =true;//All possible roads have been shown.}            }        }BOOLFlag =false; for(inti =0; I < n; i + +) { for(intj =0; J < N; J + +) {if(Eg[i][j] && eg[j][i]) {flag =true; Break; }            }if(flag) Break; }if(flag)printf("yes\n");Else printf("no\n"); }return 0;}

NOJ1119 Fairy Linding Amusement Park

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.