Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <vector>
- #include <algorithm>
- #include <math.h>
- #include <string>
- #include <set>
- #include <cstdio>
- #include <iomanip>
- #include <map>
- #include <stdio.h>
- #include <math.h>
- #include<queue>
- #define PI acos(-1.0)
- using namespace std;
- const long long inf = 10000000000;
- vector<vector<double > > table(5, vector<double>(5));
- int n;
- void input() {
- cin >> n;
- double cnt;
- for (int i = 0; i < n; i++) {
- for (int j = 0; j < n; j++) {
- cin >> cnt;
- table[i][j] = cnt;
- }
- }
- }
- void solve() {
- bool used[4];
- for (int i = 0; i < 4; i++) {
- used[i] = false;
- }
- for (int i = 0; i < n; i++) {
- vector <int> ans;
- double mult = 1;
- int first = i;
- int last = i;
- int now = rand() % n;
- for (int k = 0; k < 10000; k++) {
- while (used[now]) {
- int now = rand() % n;
- }
- mult *= table[last][now];
- last = now;
- ans.push_back(last + 1);
- if (now == first) {
- if (mult > 1) {
- cout << "YES" << "\n";
- for (int m = 0; m < ans.size(); m++) {
- cout << ans[m] << " ";
- }
- return;
- }
- else if (mult == 1) {
- ans.clear();
- mult = 1;
- for (int i = 0; i < 4; i++) {
- used[i] = false;
- }
- }
- else {
- cout << "YES" << "\n";
- for (int m = ans.size() - 1; m >= 0; m--) {
- cout << ans[m] << " ";
- }
- return;
- }
- }
- }
- }
- cout << "NO";
- }
- int main() {
- input();
- solve();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement