# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1069788 | 2024-08-22T08:56:51 Z | UmairAhmadMirza | Longest Trip (IOI23_longesttrip) | C++17 | 3 ms | 600 KB |
#include <bits/stdc++.h> using namespace std; bool are_connected(vector<int> A, vector<int> B); int const MAXN=260; int con[MAXN][MAXN]; vector<int> path,longest; bool vis[MAXN]; int nn; int is_con(int a,int b){ if(a>b) swap(a,b); if(con[a][b]==0) con[a][b]=1+(are_connected({a},{b})); return con[a][b]-1; } void dfs(int node){ path.push_back(node); if(path.size()>longest.size()) longest=path; vis[node]=1; for(int i=0;i<nn;i++) if(vis[i]==0 && is_con[node][i]) dfs(i); path.pop_back(); } vector<int> longest_trip(int n, int D){ longest.clear(); nn=n; if(D>1){ path.clear(); for (int i = 0; i < n; ++i) path.push_back(i); bool bl=0; for(int i=0;i<n-1;i++) if(is_con(path[i],path[i+1])==0){ if(i==n-2) rotate(path.rbegin(), path.rbegin() + 1, path.rend()); else swap(path[i+1],path[i+2]); } return path; } for (int i = 0; i < n; ++i) { path.clear(); for(int j=0;j<n;j++) vis[j]=0; dfs(i); if(longest.size()*2>=n) return longest; } return longest; }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 0 ms | 344 KB | Incorrect |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 3 ms | 344 KB | Output is correct |
2 | Correct | 2 ms | 344 KB | Output is correct |
3 | Correct | 1 ms | 344 KB | Output is correct |
4 | Correct | 1 ms | 600 KB | Output is correct |
5 | Correct | 2 ms | 600 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 344 KB | Output is correct |
2 | Correct | 1 ms | 344 KB | Output is correct |
3 | Correct | 1 ms | 344 KB | Output is correct |
4 | Correct | 1 ms | 344 KB | Output is correct |
5 | Correct | 3 ms | 600 KB | Output is correct |
6 | Incorrect | 1 ms | 344 KB | Incorrect |
7 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 344 KB | Output is correct |
2 | Correct | 1 ms | 344 KB | Output is correct |
3 | Correct | 1 ms | 344 KB | Output is correct |
4 | Correct | 1 ms | 344 KB | Output is correct |
5 | Correct | 1 ms | 344 KB | Output is correct |
6 | Incorrect | 1 ms | 344 KB | Incorrect |
7 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 3 ms | 344 KB | Output is correct |
2 | Correct | 1 ms | 344 KB | Output is correct |
3 | Correct | 1 ms | 344 KB | Output is correct |
4 | Correct | 1 ms | 344 KB | Output is correct |
5 | Correct | 1 ms | 344 KB | Output is correct |
6 | Incorrect | 0 ms | 344 KB | Incorrect |
7 | Halted | 0 ms | 0 KB | - |