Se da un graf orientat cu n noduri si m muchii ponderate (costurile pot fi negative). Verificati daca exista, oriunde in graf, un ciclu de cost negativ.
- Date de intrare
- Pe prima linie se citesc n si m. Urmeaza m linii, fiecare cu trei numere x y c, reprezentand o muchie orientata de la x catre y cu costul c.
- Date de iesire
- Se afiseaza 'DA' daca exista un ciclu de cost negativ, altfel 'NU'.
- Restrictii
- 1 <= n <= 200, 0 <= m <= n*(n-1), -1000 <= c <= 1000, fara autobucle
Exemple
Exemplul 1
Intrare
3 3 1 2 1 2 3 -1 3 1 -1
Iesire
DA
Exemplul 2
Intrare
3 3 1 2 1 2 3 -1 3 1 1
Iesire
NU

