Hihocoder #1174: Topology sequencing • One (judging cycle graph)

Source: Internet
Author: User
Tags in degrees

g++ 261ms 13MB

Test instructions: Given the relationship between the pre-curriculum required for the N-gate course, it is supposed to be a topological map, but because of some causes of confusion, it may not be a topological diagram. The question now is whether the graph is a topological diagram (that is, a no-loop graph).

Idea: Every time the deletion of all the 0 node, has been deleted must not have any point exists, if not the topological map of the words will have a ring, then certainly a bit of the degree is never 0. If there is no point at the end of the deletion, then it is correct.

1#include <bits/stdc++.h>2 using namespacestd;3 Const intn=100100;4 5vector< vector<int> >Vect;6 intCnt[n];//record the penetration of each point7 8 BOOLCalintN)9 {Tenvector<int> A;//points with a 0-degree deposit One      for(intI=1; i<=n; i++)//all points with a degree of 0 are found in CNT first A         if(!Cnt[i]) a.push_back (i); -vector<int> b;//temporary storage in 0 points -      while(!a.empty ()) the     { - b.clear (); -          for(intI=0; I<a.size (); i++)//point x with 0 per penetration -         { +              for(intj=0; J<vect[a[i]].size (); J + +)//each point connected to x -             { +cnt[vect[a[i]][j]]--; A                 if(!cnt[vect[a[i]][j]])//only those points that have changed are likely to be in degrees 0.  at B.push_back (Vect[a[i]][j]); -             } - vect[a[i]].clear (); -         } - a.clear (); -         if(!b.empty ()) A.insert (A.end (), B.begin (), B.end ()); in     } -      for(intI=1; I<=vect.size (); i++) to     { +         if(cnt[i]>0) -             return false; the     } *     return true; $ }Panax Notoginseng  - voidInitintN//initialized with the the { +memset (CNT,0,sizeof(CNT)); A vect.clear (); thevector<int>tmp; +      for(intI=0; i<=n; i++) - Vect.push_back (TMP); $ } $ intMain () - { -     //freopen ("E://input.txt "," R ", stdin); the     intt, N, M, A, b; -Cin>>T;Wuyi      while(t--) the     { -scanf"%d%d",&n,&m); Wu init (n); -          for(intI=0; i<m; i++) About         { $scanf"%d%d",&a,&b); - Vect[a].push_back (b); -cnt[b]++; -         } A         if(CAL (n)) +printf"correct\n"); the         Else -printf"wrong\n"); $     } the     return 0; the}
AC Code

Hihocoder #1174: Topology sequencing • One (judging cycle graph)

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.