Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- int n, m, d[100][100], sum, sm[100], u[100];
- const int INF = 1e9;
- void dfs(int v){
- if(u[v]==2&&sum-sm[v]<0){ cout << "This graph include negative cyrcle:)"; exit(0);}
- if(u[v]) return;
- u[v] = 2;
- for(int i = 0; i < n; ++i){
- if(d[v][i]!=1e5){
- sum+=d[v][i];
- if(u[i]!=2) sm[i] = sm[v]+d[v][i];
- dfs(i), sum-=d[v][i];
- }
- }
- sm[v] = 0;
- u[v] = 1;
- }
- int main(){
- ios_base::sync_with_stdio(0);
- cin.tie(0);
- cin >> n;
- for(int i = 0; i < n; ++i)
- for(int j = 0; j < n; ++j){
- cin >> d[i][j];
- }
- for(int i = 0; i < n; ++i)
- if(!u[i]) dfs(i);
- cout << "Not included:(";
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement