Submission

Status:

[PP-SSSSSSSSSSSS]

Subtask/Task Score:

{0/100}

Score: 0

User: tnka4_

Problemset: forex

Language: cpp

Time: 0.002 second

Submitted On: 2026-03-10 18:11:37

#include <iostream>
#include <vector>
#include <queue>
//#include <thread>
using namespace std;

int n, latestDepth = 0;
vector<vector<double>> adjMat;

int main() {
    cin >> n;
    adjMat.resize(n, vector<double>(n));

    for (int i=0; i<n; i++) {
        for (int j=0; j<n; j++) {
            cin >> adjMat[i][j];
        }
    }

    for (int i=0; i<n; i++) {
        //cout << "============ " << i << endl; 
        queue<vector<double>> q;
        double currentCurrency = i;
        q.push({currentCurrency, 0, 1});
        while (!q.empty()) {
            //this_thread::sleep_for(500ms);
            vector<double> current = q.front();
            q.pop();
            //cout << current[1] << " = " << current[2] << " (CURR: " << current[0] << ")" << endl;
            if (current[2] >= 1.01 && latestDepth == 0 && current[0] == currentCurrency) {
                latestDepth = current[1];
                //cout << "OK" << endl;
                break;
            }
            if (current[1] == n+1) continue;
            for (int j=0; j<n; j++) {
                double dj = j;
                q.push({dj, current[1]+1, current[2] * adjMat[current[0]][dj]});
            }
        }
        if (latestDepth != 0) {
            cout << i+1 << " " << latestDepth;
            return 0;
        }
    }
    cout << -1;
    return 0;
}


// #include <iostream>
// #include <vector>
// using namespace std;

// int n, latestDepth = 0;
// vector<vector<double>> adjMat;

// void dfs(int currentCurrency, int depth, double currentVal, int originalCurrency) {
//     cout << depth << " = " << currentVal << "(CURR: " << currentCurrency << ")" << endl;
//     if (currentVal >= 1.01 && latestDepth == 0 && currentCurrency == originalCurrency) {
//         latestDepth = depth;
//         cout << "OK" << endl;
//         return;
//     }
//     if (depth == n) return;
//     for (int i=0; i<n; i++) {
//         dfs(i, depth+1, currentVal * adjMat[currentCurrency][i], originalCurrency);
//         cout << endl;
//     }
// }

// int main() {
//     cin >> n;
//     adjMat.resize(n, vector<double>(n));

//     for (int i=0; i<n; i++) {
//         for (int j=0; j<n; j++) {
//             cin >> adjMat[i][j];
//         }
//     }

//     for (int i=0; i<n; i++) {
//         dfs(i, 0, adjMat[i][0], i);
//         if (latestDepth != 0) {
//             cout << i+1 << " " << latestDepth;
//             return 0;
//         }
//     }
//     cout << -1;
// }