Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- vector < vector <pii> > graph(2005);
- int vis[2005];
- void bellmanford(int n, int s){
- for(int i=0;i<n;i++) vis[i] = 99999999999999;
- vis[s] = 0;
- for(int i=1;i<n;i++){
- for(int j=0;j<n;j++){
- for(int k=0;k<graph[j].size();k++){
- vis[graph[j][k].first] = min(vis[graph[j][k].first], vis[j]+graph[j][k].second);
- }
- }
- }
- for(int j=0;j<n;j++){
- for(int k=0;k<graph[j].size();k++){
- if(vis[j]+graph[j][k].second<vis[graph[j][k].first]){
- cout << "possible" <<endl;
- return;
- }
- }
- }
- cout << "not possible" <<endl;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement