Submission #1052290

#TimeUsernameProblemLanguageResultExecution timeMemory
1052290ZicrusLongest Trip (IOI23_longesttrip)C++17
15 / 100
3092 ms1508 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); vector<vector<bool>> mat(n, vector<bool>(n)); 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); mat[i][j] = true; mat[j][i] = true; } 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, comp); comp = !comp; } if (k[0].size() < k[1].size()) swap(k[0], k[1]); ll mxDeg = 0, bridge = 0; for (int i = 0; i < k[0].size(); i++) { if (adj[k[0][i]].size() > mxDeg) { mxDeg = adj[k[0][i]].size(); bridge = i; } } vst = vector<bool>(n); vector<int> res; for (int i = bridge+1; i < k[0].size(); i++) { vst[k[0][i]] = true; res.push_back(k[0][i]); } for (int i = 0; i <= bridge; i++) { vst[k[0][i]] = true; res.push_back(k[0][i]); } ll used = -1; for (auto &e : adj[k[0][bridge]]) { if (vst[e]) continue; res.push_back(used = e); break; } if (used == -1) return res; for (int i = 0; i < k[1].size(); i++) { if (k[1][i] == used) { used = i; break; } } for (int i = used+1; i < k[1].size(); i++) { res.push_back(k[1][i]); } for (int i = 0; i < used; i++) { res.push_back(k[1][i]); } volatile int idk = 0; vst = vector<bool>(n); for (int i = 0; i < res.size(); i++) { while (vst[i]) idk++; vst[i] = true; if (i == 0) continue; while (!mat[res[i-1]][res[i]]) idk++; } return res; }

Compilation message (stderr)

longesttrip.cpp: In function 'std::vector<int> longest_trip(int, int)':
longesttrip.cpp:50:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   50 |     for (int i = 0; i < k[0].size(); i++) {
      |                     ~~^~~~~~~~~~~~~
longesttrip.cpp:51:33: 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]
   51 |         if (adj[k[0][i]].size() > mxDeg) {
      |             ~~~~~~~~~~~~~~~~~~~~^~~~~~~
longesttrip.cpp:59:30: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   59 |     for (int i = bridge+1; i < k[0].size(); i++) {
      |                            ~~^~~~~~~~~~~~~
longesttrip.cpp:74:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   74 |     for (int i = 0; i < k[1].size(); i++) {
      |                     ~~^~~~~~~~~~~~~
longesttrip.cpp:80:28: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   80 |     for (int i = used+1; i < k[1].size(); i++) {
      |                          ~~^~~~~~~~~~~~~
longesttrip.cpp:89:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   89 |     for (int i = 0; i < res.size(); i++) {
      |                     ~~^~~~~~~~~~~~
#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...