Advertisement
Guest User

n140.5

a guest
Jun 24th, 2017
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.62 KB | None | 0 0
  1. //
  2. // main.cpp
  3. // test
  4. //
  5. // Created by Максим Бачурин on 04.02.17.
  6. // Copyright © 2017 Максим Бачурин. All rights reserved.
  7. //
  8.  
  9. #include <iostream>
  10. #include <stdio.h>
  11. #include <cstring>
  12. #include <string>
  13. #include <vector>
  14. #include <algorithm>
  15. #include <cmath>
  16. #include <utility>
  17. #include <set>
  18. #include <map>
  19. #include <list>
  20. #include <queue>
  21. #include <iomanip>
  22. #include <sstream>
  23. #include <fstream>
  24. using namespace std;
  25. #define all(x) (x).begin(),(x).end()
  26. #define SZ(x) ((int)(x).size())
  27. #define FILE "sum"
  28. typedef vector<int> VI;
  29. typedef long long ll;
  30. typedef unsigned long long ull;
  31. typedef pair<int, int> PII;
  32. const ll mod = 1e9 + 7;
  33. //const double eps = 1e-9;
  34. const int inf = 1e9;
  35. //const double PI = 3.1415926535897932384626433832795;
  36. const int N = 100005;
  37.  
  38. int d[101][101];
  39.  
  40. int main()
  41. {
  42. //freopen(FILE".in", "r", stdin);
  43. //freopen(FILE".out", "w", stdout);
  44. ios_base::sync_with_stdio(0);
  45. int n;
  46. cin >> n;
  47. for(int i = 0; i < n; i++)
  48. {
  49. for(int j = 0; j < n; j++)
  50. {
  51. int a;
  52. cin >> a;
  53. d[i][j] = a;
  54. if(!a && i != j)
  55. d[i][j] = inf;
  56. }
  57. }
  58. for(int k = 0; k < n; k++)
  59. for(int i = 0; i < n; i++)
  60. for(int j = 0; j < n; j++)
  61. {
  62. if(d[i][k] < inf && d[k][j] < inf)
  63. d[i][j] = max(-inf, min(d[i][j], d[i][k] + d[k][j]));
  64. }
  65. for(int i = 0; i < n; i++)
  66. {
  67. if(d[i][i] < 0)
  68. return cout << "YES", 0;
  69. }
  70. cout << "NO";
  71. return 0;
  72. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement