Poj 2983 is the information reliable?

Source: Internet
Author: User

Poj_2983

With the foundation of the previous questions, this question is quite well thought. We set S [I] Point I Distance to a reference point on a straight line (you can set 0 As a reference point), in order to write the question, simply put the question A north
B Imagine it all B South than , If it is input P There should be two constrained equations. S [B]-s [a]> = x , S [a]-s [B]> =-x And input V Only corresponds to one constrained equation. S [B]-s [a]> = 1 .

Then, if we use the shortest short circuit, we will actually judge whether there is a negative circle in this graph. To make the Graph Connected, we abstract a source point. 0 To any point I All have S [I]-s [0]> = 0 In this way, the graph is connected. 0 Start point. You can check whether there is a negative circle.

 # Include  <  Stdio. h  >  
# Include < String . H >
Int First [ 1010 ], Next [ 210000 ], V [ 210000 ], W [ 210000 ];
Int D [ 1010 ], Q [ 1010 ], INQ [ 1010 ], Inedq [ 1010 ];
Char B [ 5 ];
Int Main ()
{
Int I, J, K, a, B, X, n, m, U, E, OK, N, front, rear;
While (Scanf ( " % D " , & N, & M) = 2 )
{
E = 0 ;
Memset (first, - 1 , Sizeof (First ));
For (I = 0 ; I < M; I ++ )
{
Scanf ( " % S " , B );
If (B [ 0 ] = ' V ' )
{
Scanf ( " % D " , & A, & B );
V [E] = A;
W [E] =- 1 ;
Next [E] = First [B];
First [B] = E;
E ++ ;
}
Else If (B [ 0 ] = ' P ' )
{
Scanf ( " % D " , & A, & B, & X );
V [E] = A;
W [E] =- X;
Next [E] = First [B];
First [B] = E;
E ++ ;
V [E] = B;
W [E] = X;
Next [E] = First [a];
First [A] = E;
E ++ ;
}
}
For (I = 1 ; I <= N; I ++ )
{
V [E] = I;
W [E] = 0 ;
Next [E] = First [ 0 ];
First [ 0 ] = E;
E ++ ;
}
For (I = 0 ; I <= N; I ++ )
{
D [I] = 1000000000 ;
INQ [I] = Inedq [I] = 0 ;
}
D [ 0 ] = 0 ;
Front = Rear = 0 ;
Q [rear ++ ] = 0 ;
OK = 1 ;
N = N + 1 ;
While (Front ! = Rear)
{
U = Q [Front ++ ];
INQ [u] = 0 ;
If (Front > N)
Front = 0 ;
For (E = First [u]; e ! =- 1 ; E = Next [e])
If (D [u] + W [E] < D [V [e])
{
D [V [e] = D [u] + W [E];
If ( ! INQ [V [e])
{
Q [rear ++ ] = V [E];
If (Rear > N)
Rear = 0 ;
INQ [V [e] = 1 ;
If ( ++ Inedq [V [e] > N)
{
OK = 0 ;
Front = Rear;
Break ;
}
}
}
}
If (OK)
Printf ( " Reliable \ n " );
Else
Printf ( " Unreliable \ n " );
}
Return 0 ;
}

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.