PKU 2594 Floyd + minimum path Overwrite

Source: Internet
Author: User
PKU 2594 indicates that a directed acyclic graph is given, and the entire graph is overwritten with the least path. The path allows vertex intersection.

At first glance, this question seems to be the minimum path coverage, but it takes a while to allow vertex intersection. To put it bluntly, since the vertex intersection is allowed, the connectivity should also be passed, so that the connectivity can be changed to the standard minimum path overwrite question. Code Only once, my code is ugly. Code
1 /// Loves DL ~~
2
3 # Include < Iostream >
4 # Include < Algorithm >
5
6 Using   Namespace STD;
7
8 Const   Int Maxn = 510 ;
9 Bool Gg [maxn] [maxn];
10 Int Link [maxn];
11 Bool S [maxn];
12 Int M, N;
13
14 Bool Find ( Int X)
15 {
16 Int I;
17 For (I = 1 ; I <= N; I ++ ){
18 If (( ! S [I]) && Gg [x] [I]) {
19 S [I] = True ;
20 If (Link [I] = 0 | Find (link [I]) {
21 Link [I] = X;
22 Return   True ;
23 }
24 }
25 }
26 Return   False ;
27 }
28
29 Int Main ()
30 {
31 Freopen ( " In.txt " , " R " , Stdin );
32 While (Scanf ( " % D " , & N, & M) ! = EOF &&! (M = 0 && N = 0 ))
33 {
34 Memset (Gg, 0 , Sizeof (Gg ));
35 Memset (link, 0 , Sizeof (Link ));
36 Int I, J, K;
37 Int St, E;
38 For (I = 0 ; I < M; I ++ )
39 {
40 Scanf ( " % D " , & St, & E );
41 Gg [st] [E] = True ;
42 }
43 /// /Floyd evaluate the passing Closure
44 For (K = 1 ; K <= N; k ++ )
45 {
46 For (I = 1 ; I <= N; I ++ )
47 {
48 For (J = 1 ; J <= N; j ++ )
49 {
50 If (Gg [I] [k] && Gg [k] [J] &&! Gg [I] [J])
51 Gg [I] [J] = True ;
52 }
53 }
54 }
55 /// /Find the minimum path Overwrite
56 Int Ans = 0 ;
57 For (I = 1 ; I <= N; I ++ )
58 {
59 Memset (S, False , Sizeof (S ));
60 If (Find (I ))
61 {
62 Ans ++ ;
63 }
64 }
65 Printf ( " % D \ n " , N - Ans );
66 }
67
68 Return   0 ;
69

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.