Submission #841417

# Submission time Handle Problem Language Result Execution time Memory
841417 2023-09-01T15:39:35 Z flashmt Longest Trip (IOI23_longesttrip) C++17
Compilation error
0 ms 0 KB
#include <bits/stdc++.h>
using namespace std;

vector<int> longest_trip(int n, int d)
{
  vector<vector<int>> a(n, vector<int>(n));
  for (int i = 0; i < n; i++)
    for (int j = i + 1; j < n; j++)
      a[i][j] = a[j][i] = are_connected({i}, {j});

  for (int i = 0; i < n; i++)
    for (int j = 0; j < n; j++)
      for (int k = 0; k < n; k++)
        if (a[i][j] && a[j][k])
        {
          deque<int> q;
          q.push_back(i);
          q.push_back(j);
          q.push_back(k);
          for (int p = 0; p < n; p++)
            if (p != i && p != j && p != k)
            {
              if (a[p][q.back()]) q.push_back(p);
              else
              {
                assert(a[p][q.front()]);
                q.push_front(p);
              }
            }

          vector<int> ans;
          while (!empty(q))
          {
            ans.push_back(q.front());
            q.pop_front();
          }
          assert(size(ans) == n);
          return ans;
        }

  for (int i = 0; i < n; i++)
    for (int j = i + 1; j < n; j++)
      if (a[i][j])
      {
        return {i, j};
      }

  assert(0);
  return {};
}

Compilation message

longesttrip.cpp: In function 'std::vector<int> longest_trip(int, int)':
longesttrip.cpp:9:27: error: 'are_connected' was not declared in this scope
    9 |       a[i][j] = a[j][i] = are_connected({i}, {j});
      |                           ^~~~~~~~~~~~~
In file included from /usr/include/c++/10/cassert:44,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:33,
                 from longesttrip.cpp:1:
longesttrip.cpp:37:28: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   37 |           assert(size(ans) == n);
      |                  ~~~~~~~~~~^~~~