Submission #842023

#TimeUsernameProblemLanguageResultExecution timeMemory
842023Tenis0206Longest Trip (IOI23_longesttrip)C++17
0 / 100
7 ms344 KiB
#include <bits/stdc++.h> #include "longesttrip.h" using namespace std; const int nmax = 256; int n; std::vector<int> G[nmax + 5]; vector<int> r; int d[nmax + 5]; void bfs(int nod) { queue<int> q; for(int i=0;i<n;i++) { d[i] = 0; } d[nod] = 1; q.push(nod); while(!q.empty()) { nod = q.front(); q.pop(); for(auto it : G[nod]) { if(d[it]) { continue; } d[it] = 1 + d[nod]; q.push(it); } } for(int i=0;i<n;i++) { if(d[i] > d[nod]) { nod = i; } } vector<int> aux; aux.push_back(nod); while(d[nod]!=1) { for(auto it : G[nod]) { if(d[it]==d[nod] - 1) { nod = it; break; } } aux.push_back(nod); } if(aux.size() > r.size()) { r = aux; } } std::vector<int> longest_trip(int N, int D) { n = N; r.clear(); for(int i=0;i<n;i++) { G[i].clear(); } for(int i=0; i<n; i++) { for(int j=i+1; j<n; j++) { if(are_connected({i}, {j})) { G[i].push_back(j); G[j].push_back(i); } } } for(int i=0;i<n;i++) { bfs(i); } return r; }
#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...