Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <string>
- #include <fstream>
- #include <queue>
- using namespace std;
- const int N = 1111;
- int n;
- double a[N][N];
- bool calc() {
- bool ok = 0;
- for (int k = 0; k < n; ++k)
- for (int i = 0; i < n; ++i)
- for (int j = 0; j < n; ++j)
- if (a[i][k] * a[k][j] > a[i][j]) {
- ok = 1;
- a[i][j] = a[i][k] * a[k][j];
- }
- for (int i = 0; i < n && ok; ++i)
- if (a[i][i] > 1) ok = 0;
- return ok;
- }
- int main(){
- ifstream fin("in.txt");
- ofstream fout("out.txt");
- fin >> n;
- for (int i = 0; i < n; ++i)
- for (int j = 0; j < n; ++j)
- fin >> a[i][j];
- while (calc());
- for (int i = 0; i < n; ++i)
- if (a[i][i] > 1) {
- fout << "yes";
- return 0;
- }
- fout << "no";
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement