Grafs (1) P56483


Statement
 

pdf   zip

Donat un graf dirigit amb nn vèrtexs i mm arcs, es vol saber si hi ha un camí dirigit entre dos vèrtexs.

Entrada

L’entrada comença amb nn i mm. Segueixen mm parells u,vu,v, amb uvu \ne v, indicant un arc de uu a vv. Es té 0u<n0\le u<n i 0v<n0\le v<n i no hi ha arcs repetits. A continuació ve un parell x,yx,y amb 0x<n0\le x<n i 0y<n0\le y <n.

Sortida

Escriviu “yes” o “no” depenent de si hi ha o no un camí de xx a yy.

Public test cases
  • Input

    8 10
    1 4  4 6  7 2  7 5  0 3  2 5  5 2  6 3  1 0  0 1
    1 3
    

    Output

    yes
    
  • Input

    8 10
    1 4  4 6  7 2  7 5  0 3  2 5  5 2  6 3  1 0  0 1
    7 6
    

    Output

    no
    
  • Information
    Author
    Jordi Petit
    Language
    Catalan
    Other languages
    English
    Official solutions
    C++ Python Python
    User solutions
    C++ Python