Submission #840737

# Submission time Handle Problem Language Result Execution time Memory
840737 2023-08-31T16:26:50 Z hcng Longest Trip (IOI23_longesttrip) C++17
0 / 100
1000 ms 556 KB
#include <bits/stdc++.h>
#include "longesttrip.h"

using namespace std;

void dfs(int u, int n, vector<int> &cur, vector<int> &vis, vector<int> &ret, vector<vector<bool>> &a) {
    vis[u] = true;
    cur.push_back(u);
    bool flag = true;
    for (int v = 0; v < n; v++) {
        if (a[u][v] && !vis[v]) {
            dfs(v, n, cur, vis, ret, a);
            flag = false;
        }
    }
    if (flag) {
        if (cur.size() > ret.size()) {
            ret = cur;
        }
    }
    cur.pop_back();
    vis[u] = false;
}

vector<int> longest_trip(int n, int d) {
    vector<vector<bool>> a(n, vector<bool>(n));
    for (int i = 0; i < n; i++) {
        for (int j = i + 1; j < n; j++) {
            a[i][j] = are_connected({i}, {j});
            a[j][i] = a[i][j];
        }
    }
    vector<vector<int>> dis(n, vector<int>(n, -1));
    vector<int> ret, cur, vis(n);
    for (int i = 0; i < n; i++) {
        dfs(i, n, cur, vis, ret, a);
    }
    return ret;
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 208 KB Output is correct
2 Execution timed out 3070 ms 556 KB Time limit exceeded
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 14 ms 208 KB Output is correct
2 Execution timed out 3068 ms 208 KB Time limit exceeded
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 10 ms 208 KB Output is correct
2 Execution timed out 3076 ms 208 KB Time limit exceeded
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 12 ms 208 KB Output is correct
2 Execution timed out 3037 ms 208 KB Time limit exceeded
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 14 ms 208 KB Output is correct
2 Execution timed out 3067 ms 208 KB Time limit exceeded
3 Halted 0 ms 0 KB -