제출 #1311216

#제출 시각아이디문제언어결과실행 시간메모리
1311216moha1111기지국 (IOI20_stations)C++20
컴파일 에러
0 ms0 KiB
#include "bits/stdc++.h"
#include "stations.h"
using namespace std;

int time;

void dfs(int node , vector<int>& lab , vector<vector<int>>& graph , bool dip , vector<int> &vis)
{
    if(dip == 0)
        lab[node] = time;
        
    time++;
        
    vis[node] = 1;
        
    for(auto i : graph[node])
    {
        if(vis[i] == 0)
            dfs(i , lab , graph , dip ^ 1 , vis);
    }
    if(dip == 1)
        lab[node] = time;

    time++;
}

vector<int> label(int n, int k, vector<int> u, vector<int> v)
{
    vector<vector<int>> graph(n + 5);
    for(int i = 1 ; i < n ; i++)
    {
        graph[u[i]].push_back(v[i]);
        graph[v[i]].push_back(u[i]);
    }
    vector<int> lab(n + 5) , vis(n + 5);
    dfs(0 , lab , graph , 0 , vis);
    return lab;
}

int find_next_station(int s, int t, vector<int> c)
{
    if(c.size() == 1)
        return c[0];
    
    if(s < c[0])
    {
        /// start
        int p = -1;
        for(int i = 0 ; i < c.size() - 1 ; i++)
        {
            int st , en = c[i];
            if(p == -1)
                st = s + 1;
            
            else
                st = p + 1;
            
            if(st <= t && t <= en)
                return c[i];
            
            p = c[i];
        }
        return c.back();
    }
    /// end
    int p = -1;
    for(int i = c.size() - 1 ; i >= 1 ; i--)
    {
        int st = c[i] , en;
        if(p == -1)
            en = s - 1;
        
        else
            en = p - 1;
        
        if(st <= t && t <= en)
            return c[i];
        
        p = c[i];
    }
    return c[0];
}

컴파일 시 표준 에러 (stderr) 메시지

stations.cpp:5:5: error: 'int time' redeclared as different kind of entity
    5 | int time;
      |     ^~~~
In file included from /usr/include/pthread.h:23,
                 from /usr/include/x86_64-linux-gnu/c++/13/bits/gthr-default.h:35,
                 from /usr/include/x86_64-linux-gnu/c++/13/bits/gthr.h:148,
                 from /usr/include/c++/13/ext/atomicity.h:35,
                 from /usr/include/c++/13/bits/ios_base.h:39,
                 from /usr/include/c++/13/streambuf:43,
                 from /usr/include/c++/13/bits/streambuf_iterator.h:35,
                 from /usr/include/c++/13/iterator:66,
                 from /usr/include/x86_64-linux-gnu/c++/13/bits/stdc++.h:54,
                 from stations.cpp:1:
/usr/include/time.h:76:15: note: previous declaration 'time_t time(time_t*)'
   76 | extern time_t time (time_t *__timer) __THROW;
      |               ^~~~
stations.cpp: In function 'void dfs(int, std::vector<int>&, std::vector<std::vector<int> >&, bool, std::vector<int>&)':
stations.cpp:10:21: error: invalid conversion from 'time_t (*)(time_t*) noexcept' {aka 'long int (*)(long int*) noexcept'} to '__gnu_cxx::__alloc_traits<std::allocator<int>, int>::value_type' {aka 'int'} [-fpermissive]
   10 |         lab[node] = time;
      |                     ^~~~
      |                     |
      |                     time_t (*)(time_t*) noexcept {aka long int (*)(long int*) noexcept}
stations.cpp:12:5: warning: ISO C++ forbids incrementing a pointer of type 'time_t (*)(time_t*) noexcept' {aka 'long int (*)(long int*) noexcept'} [-Wpointer-arith]
   12 |     time++;
      |     ^~~~
stations.cpp:12:5: error: lvalue required as increment operand
stations.cpp:22:21: error: invalid conversion from 'time_t (*)(time_t*) noexcept' {aka 'long int (*)(long int*) noexcept'} to '__gnu_cxx::__alloc_traits<std::allocator<int>, int>::value_type' {aka 'int'} [-fpermissive]
   22 |         lab[node] = time;
      |                     ^~~~
      |                     |
      |                     time_t (*)(time_t*) noexcept {aka long int (*)(long int*) noexcept}
stations.cpp:24:5: warning: ISO C++ forbids incrementing a pointer of type 'time_t (*)(time_t*) noexcept' {aka 'long int (*)(long int*) noexcept'} [-Wpointer-arith]
   24 |     time++;
      |     ^~~~
stations.cpp:24:5: error: lvalue required as increment operand