Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //
- // main.cpp
- // test
- //
- // Created by Максим Бачурин on 04.02.17.
- // Copyright © 2017 Максим Бачурин. All rights reserved.
- //
- #include <iostream>
- #include <stdio.h>
- #include <cstring>
- #include <string>
- #include <vector>
- #include <algorithm>
- #include <cmath>
- #include <utility>
- #include <set>
- #include <map>
- #include <list>
- #include <queue>
- #include <iomanip>
- #include <sstream>
- #include <fstream>
- using namespace std;
- #define all(x) (x).begin(),(x).end()
- #define SZ(x) ((int)(x).size())
- #define FILE "sum"
- typedef vector<int> VI;
- typedef long long ll;
- typedef unsigned long long ull;
- typedef pair<int, int> PII;
- const ll mod = 1e9 + 7;
- //const double eps = 1e-9;
- const int inf = 1e9;
- //const double PI = 3.1415926535897932384626433832795;
- const int N = 100005;
- int d[101][101];
- int main()
- {
- //freopen(FILE".in", "r", stdin);
- //freopen(FILE".out", "w", stdout);
- ios_base::sync_with_stdio(0);
- int n;
- cin >> n;
- for(int i = 0; i < n; i++)
- {
- for(int j = 0; j < n; j++)
- {
- int a;
- cin >> a;
- d[i][j] = a;
- if(!a && i != j)
- d[i][j] = inf;
- }
- }
- for(int k = 0; k < n; k++)
- for(int i = 0; i < n; i++)
- for(int j = 0; j < n; j++)
- {
- if(d[i][k] < inf && d[k][j] < inf)
- d[i][j] = max(-inf, min(d[i][j], d[i][k] + d[k][j]));
- }
- for(int i = 0; i < n; i++)
- {
- if(d[i][i] < 0)
- return cout << "YES", 0;
- }
- cout << "NO";
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement