mirror of
https://github.com/Hizenberg469/Algorithms-snippets.git
synced 2026-04-20 07:02:23 +03:00
19 lines
264 B
C++
19 lines
264 B
C++
vector<int> dist(n+1,(int)-1e17);
|
|
|
|
dist[1]=0;
|
|
|
|
for(int i = 1 ; i < n ; i++ ){
|
|
for(auto& e : g ){
|
|
int a,b,w;
|
|
tie(a,b,w)=e;
|
|
dist[b]=max(dist[b],dist[a]+w);
|
|
}
|
|
}
|
|
|
|
for(auto& e : g ){
|
|
int a,b,w;
|
|
tie(a,b,w)=e;
|
|
if( dist[b] < dist[a] + w ){
|
|
cycle[b]=true;
|
|
}
|
|
} |