Submission #1049361

#TimeUsernameProblemLanguageResultExecution timeMemory
1049361ZicrusLongest Trip (IOI23_longesttrip)C++17
15 / 100
731 ms1696 KiB
#include <bits/stdc++.h> #include "longesttrip.h" using namespace std; typedef long long ll; vector<vector<ll>> adj, noAdj; vector<bool> vst; vector<vector<ll>> k; void dfs(ll cur, ll comp) { vst[cur] = true; k[comp].push_back(cur); for (auto &e : noAdj[cur]) { if (vst[e]) continue; dfs(e, !comp); } } vector<int> longest_trip(int n, int d) { adj = vector<vector<ll>>(n); noAdj = vector<vector<ll>>(n); k = vector<vector<ll>>(2); for (int i = 0; i < n; i++) { for (int j = i+1; j < n; j++) { if (are_connected({i}, {j})) { adj[i].push_back(j); adj[j].push_back(i); } else { noAdj[i].push_back(j); noAdj[j].push_back(i); } } } vst = vector<bool>(n); ll comp = 0; for (int i = 0; i < n; i++) { if (vst[i]) continue; dfs(i, 0); comp = !comp; } if (k[0].size() < k[1].size()) swap(k[0], k[1]); ll mxDeg = 0, bridge = 0; for (auto &e : k[0]) { if (adj[e].size() > mxDeg) { mxDeg = adj[e].size(); bridge = e; } } vst = vector<bool>(n); vector<int> res; for (auto &e : k[0]) { vst[e] = true; if (e == bridge) continue; res.push_back(e); } res.push_back(bridge); ll used = -1; for (auto &e : adj[bridge]) { if (vst[e]) continue; res.push_back(used = e); break; } if (used == -1) return res; for (auto &e : k[1]) { if (e == used) continue; res.push_back(e); } return res; }

Compilation message (stderr)

longesttrip.cpp: In function 'std::vector<int> longest_trip(int, int)':
longesttrip.cpp:48:27: warning: comparison of integer expressions of different signedness: 'std::vector<long long int>::size_type' {aka 'long unsigned int'} and 'll' {aka 'long long int'} [-Wsign-compare]
   48 |         if (adj[e].size() > mxDeg) {
      |             ~~~~~~~~~~~~~~^~~~~~~
#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...