Submission #1069821

#TimeUsernameProblemLanguageResultExecution timeMemory
1069821UmairAhmadMirzaLongest Trip (IOI23_longesttrip)C++17
40 / 100
691 ms1380 KiB
#include <bits/stdc++.h> using namespace std; bool are_connected(vector<int> A, vector<int> B); int const MAXN=260; int con[MAXN][MAXN]; bool dn[MAXN][MAXN]; vector<int> path,longest; bool vis[MAXN]; int nn; bool is_con(int a,int b){ if(a>b) swap(a,b); if(dn[a][b]==0){ con[a][b]=are_connected({a},{b}); dn[a][b]=1; } return con[a][b]; } 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)==1) dfs(i); path.pop_back(); } vector<int> longest_trip(int n, int D){ for (int i = 0; i < n; ++i) for(int j=0;j<n;j++){ dn[i][j]=0; } 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 (stderr)

longesttrip.cpp: In function 'std::vector<int> longest_trip(int, int)':
longesttrip.cpp:42:8: warning: unused variable 'bl' [-Wunused-variable]
   42 |   bool bl=0;
      |        ^~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...