# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
840880 | 2023-08-31T19:56:52 Z | Minindu206 | Longest Trip (IOI23_longesttrip) | C++17 | 1000 ms | 844 KB |
#include "longesttrip.h" #include <bits/stdc++.h> using namespace std; int mxlen = INT_MIN; vector<int> ans; void dfs(vector<int> adj[], int node, vector<int> &vis, vector<int> temp) { //cout << temp.size() << '\n'; if((int)temp.size() > mxlen) { // cout << 'x'; mxlen = temp.size(); ans.clear(); ans = temp; } else if(temp.size() == mxlen) { ans.clear(); ans = temp; } for(auto a:adj[node]) { if(vis[a]) continue; temp.push_back(a); vis[a] = 1; dfs(adj, a, vis, temp); temp.pop_back(); vis[a] = 0; } } vector<int> longest_trip(int n, int d) { vector<int> adj[n]; for (int i = 0; i < n - 1; i++) { for (int j = i + 1; j < n; j++) { if (are_connected({i}, {j})) { adj[i].push_back(j); adj[j].push_back(i); } } } vector<int> vis, temp; for (int i = 0; i < n; i++) { temp.clear(); vis.resize(n, 0); temp.push_back(i); vis[i] = 1; dfs(adj, i, vis, temp); if(mxlen >= n / 2) { break; } } // cout << "MAX:-" << mxlen << '\n'; mxlen = -1; return ans; }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 208 KB | Output is correct |
2 | Execution timed out | 3015 ms | 844 KB | Time limit exceeded |
3 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 9 ms | 208 KB | Output is correct |
2 | Execution timed out | 3054 ms | 208 KB | Time limit exceeded |
3 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 6 ms | 208 KB | Output is correct |
2 | Execution timed out | 3090 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 | 3050 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 | 3045 ms | 208 KB | Time limit exceeded |
3 | Halted | 0 ms | 0 KB | - |