Kuangbin_shortpathh (POJ 3660)

Source: Internet
Author: User

Originally wanted to write a bfs to let him follow the outcome of the climb to the corner of the decision can not determine the order

And then I find out that there are extra sides that don't omit to write an O (n^3) to erase the extra edges, which is not as good as Floyd.

See Shang Seniors write is topological sequence also can solve and in understanding his article when the IQ offline Floyd didn't recognize

Finally I wrote a (standard) Floyd gorgeous WA and then find out is I j K sequence written bad Hmm, the original algorithm or to review the

Have time to learn more about topological sequencing solutions

#include <cstdio>#include<cstring>intMain () {intmap[ the][ the]; intN, M; memset (Map,0,sizeofmap); scanf ("%d%d", &n, &m);  while(m--){        intA, B; scanf ("%d%d", &a, &b); MAP[A][B]=1; }     for(inti =1; I <= N; i++){         for(intj =1; J <= N; J + +){             for(intK =1; K <= N; k++){                if(Map[j][i] &&Map[i][k]) {Map[j][k]=1; }            }        }    }    intres =0;  for(inti =1; I <= N; i++){        intCount =0;  for(intj =1; J <= N; J + +) {Count+ = Map[i][j] +Map[j][i]; }        if(count = = N-1) res++; } printf ("%d\n", RES); return 0;}

Kuangbin_shortpathh (POJ 3660)

Related Keywords:

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.