Submission

Status:

[PPPPTSSSSSSSSSS]

Subtask/Task Score:

{0/100}

Score: 0

User: poni

Problemset: forex

Language: cpp

Time: 1.093 second

Submitted On: 2026-10-18 15:20:28

#include <bits/stdc++.h>

using namespace std;
#define int long long
#define INF 2e15;
#define vi vector<double>
#define pii pair<int, double>
#define pvi pair<vector<int>, double>

signed main() {
    cin.tie(0)->sync_with_stdio(0);
    int n;
    cin >> n;

    vector<vector<pii>> v(n);
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < n; j++) {
            double x;
            cin >> x;
            if (i != j) v[i].emplace_back(j, x);
        }
    }

    int mn = INF;
    int ans = -1;
    for (int i = 0; i < n; i++) {
        stack<pvi> st;
        st.push({{i}, 1.0});

        while (!st.empty()) {
            auto [cpath, cprof] = st.top();
            st.pop();
            int cur = cpath.back();

            for (auto [nxt, w] : v[cur]) {
                double nprof = cprof * w;
                if (nxt == i && nprof > 1.01 && cpath.size() < mn) {
                    mn = cpath.size();
                    ans = nxt;
                }

                if (nxt != i && find(cpath.begin(), cpath.end(), nxt) != cpath.end()) continue;
                vector<int> npath = cpath;
                npath.emplace_back(nxt);

                st.push({npath, nprof});
            }
        }
        
    }
    if (ans != -1) cout << ans+1 << ' ' << mn;
    else cout << -1;
}