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