Submission #988607

#TimeUsernameProblemLanguageResultExecution timeMemory
988607GrayLongest Trip (IOI23_longesttrip)C++17
5 / 100
755 ms2348 KiB
#include "longesttrip.h" #include<bits/stdc++.h> #include <cassert> using namespace std; #define ll long long #define ff first #define ss second #define ln endl vector<vector<ll>> A; ll n, d; void dfs(ll u, vector<bool> &vis, vector<int> &trip){ trip.push_back(u); vis[u]=1; for (auto v:A[u]){ if (!vis[v]){ dfs(v, vis, trip); } } } std::vector<int> longest_trip(int N, int D) { n=N; d=D; A.clear(); A.resize(N); for (ll i=0; i<n; i++){ for (ll j=i+1; j<n; j++){ if (are_connected({(int)i}, {(int)j})){ A[i].push_back(j); A[j].push_back(i); } } } vector<ll> semi; for (ll i=0; i<n; i++){ if (A[i].size()<n-1){ semi.push_back(i); } } // assert(semi.size()>=0 and semi.size()<=2); vector<int> ans; if (semi.size()==2){ ans.push_back(semi[0]); for (ll i=0; i<n; i++){ if (i!=semi[0] and i!=semi[1]){ ans.push_back(i); } } ans.push_back(semi[1]); }else{ vector<bool> vis(n); for (ll i=0; i<n; i++){ if (vis[i]==0){ vector<int> trip; dfs(i, vis, trip); if (ans.size()<trip.size()){ ans=trip; } } } } return ans; }

Compilation message (stderr)

longesttrip.cpp: In function 'std::vector<int> longest_trip(int, int)':
longesttrip.cpp:35:24: warning: comparison of integer expressions of different signedness: 'std::vector<long long int>::size_type' {aka 'long unsigned int'} and 'long long int' [-Wsign-compare]
   35 |         if (A[i].size()<n-1){
      |             ~~~~~~~~~~~^~~~
#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...