Submission #842018

# Submission time Handle Problem Language Result Execution time Memory
842018 2023-09-02T10:13:01 Z Tenis0206 Longest Trip (IOI23_longesttrip) C++17
Compilation error
0 ms 0 KB
#include <bits/stdc++.h>
#include "longesttrip.h"

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;
    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;
}

Compilation message

longesttrip.cpp:10:1: error: 'vector' does not name a type
   10 | vector<int> r;
      | ^~~~~~
longesttrip.cpp: In function 'void bfs(int)':
longesttrip.cpp:16:5: error: 'queue' was not declared in this scope; did you mean 'std::queue'?
   16 |     queue<int> q;
      |     ^~~~~
      |     std::queue
In file included from /usr/include/c++/10/queue:64,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:86,
                 from longesttrip.cpp:1:
/usr/include/c++/10/bits/stl_queue.h:96:11: note: 'std::queue' declared here
   96 |     class queue
      |           ^~~~~
longesttrip.cpp:16:11: error: expected primary-expression before 'int'
   16 |     queue<int> q;
      |           ^~~
longesttrip.cpp:22:5: error: 'q' was not declared in this scope
   22 |     q.push(nod);
      |     ^
longesttrip.cpp:44:5: error: 'vector' was not declared in this scope
   44 |     vector<int> aux;
      |     ^~~~~~
longesttrip.cpp:44:5: note: suggested alternatives:
In file included from /usr/include/c++/10/vector:67,
                 from /usr/include/c++/10/functional:62,
                 from /usr/include/c++/10/pstl/glue_algorithm_defs.h:13,
                 from /usr/include/c++/10/algorithm:74,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:65,
                 from longesttrip.cpp:1:
/usr/include/c++/10/bits/stl_vector.h:389:11: note:   'std::vector'
  389 |     class vector : protected _Vector_base<_Tp, _Alloc>
      |           ^~~~~~
In file included from /usr/include/c++/10/functional:62,
                 from /usr/include/c++/10/pstl/glue_algorithm_defs.h:13,
                 from /usr/include/c++/10/algorithm:74,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:65,
                 from longesttrip.cpp:1:
/usr/include/c++/10/vector:86:13: note:   'std::pmr::vector'
   86 |       using vector = std::vector<_Tp, polymorphic_allocator<_Tp>>;
      |             ^~~~~~
longesttrip.cpp:44:12: error: expected primary-expression before 'int'
   44 |     vector<int> aux;
      |            ^~~
longesttrip.cpp:45:5: error: 'aux' was not declared in this scope
   45 |     aux.push_back(nod);
      |     ^~~
longesttrip.cpp:58:21: error: 'r' was not declared in this scope
   58 |     if(aux.size() > r.size())
      |                     ^
longesttrip.cpp: In function 'std::vector<int> longest_trip(int, int)':
longesttrip.cpp:82:12: error: 'r' was not declared in this scope
   82 |     return r;
      |            ^