제출 #1168794

#제출 시각아이디문제언어결과실행 시간메모리
1168794sitablechair기지국 (IOI20_stations)C++20
컴파일 에러
0 ms0 KiB
#include <iostream>
#include <algorithm>
#include <vector>
#include "stations.h"

using namespace std;

const int N=100003;

int tdfs=0,tin[N*2],tout[N*2],d[N];
vector<int> big,ans,g[N];

void dfs(int u,int p=0) {
    tin[u]=++tdfs;
    for(auto v: g[u])
        if (v!=p) {
            d[v]=d[u]+1;
            dfs(v,u);
        }
    tout[u]=++tdfs;
}

vector<int> label(int n,int k,vector<int> u,vector<int> v) {
    ans.resize(n);
    For(i,0,n-1) g[i].clear();
    big.clear();
    tdfs=-1;
    For(i,0,n-2) {
        g[u[i]].pb(v[i]);
        g[v[i]].pb(u[i]);
    }
    dfs(0);
    //cout << "tin: " << tin[0] << endl;
    For(i,0,n-1)
        if (d[i]&1) big.pb(tin[i]);
        else big.pb(tout[i]);
    sort(all(big));
    unq(big);
    For(i,0,n-1)
        if (d[i]&1) {
            ans[i]=lower_bound(all(big),tout[i])-big.begin();
        }
        else {
            ans[i]=lower_bound(all(big),tin[i])-big.begin();
            //cout << i << " " << tout[i] << endl;
        }
    return ans;
}
int find_next_station(int s,int t,vector<int> c) {
    bool check=1;
    sort(all(c));
    for(auto u: c) {
        //cout << "u: " <<  u << endl;
        if (t==u) return t;
        if (u>s) check=0;
    }
    if (sz(c)==1) return c.back();
    if (s==0) {
        for(int i=0;i<sz(c);i++) {
            int prv=(i==0?1:c[i-1]+1);
            if (t<=c[i] && t>=prv) return c[i];
        }
    }
    if (check) {
        int mi=*min_element(all(c));
        int mi1=2e9;
        for(auto u: c)
            if (u!=mi && u<mi1) mi1=u;
        if (t<s && t>mi1) {
            for(int i=0;i<sz(c);i++) {
                if (c[i]==mi) continue;
                int nxt=(i==sz(c)-1?s:c[i+1]-1);
                if (t>=c[i] && t<=nxt) return c[i];
            }
        } else return mi;
    } else {
        int ma=*max_element(all(c));
        int ma1=-2e9;
        for(auto u: c)
            if (u!=ma && u>ma1) ma1=u;
        if (t>s && t<ma1) {
            for(int i=0;i<sz(c);i++) {
                if (c[i]==ma) continue;
                int prv=(i==0?s+1:c[i-1]+1);
                if (t>=prv && t<=c[i]) return c[i];
            }
        } else return ma;
    }
}

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

stations.cpp: In function 'std::vector<int> label(int, int, std::vector<int>, std::vector<int>)':
stations.cpp:25:9: error: 'i' was not declared in this scope
   25 |     For(i,0,n-1) g[i].clear();
      |         ^
stations.cpp:25:5: error: 'For' was not declared in this scope
   25 |     For(i,0,n-1) g[i].clear();
      |     ^~~
stations.cpp:36:9: error: 'else' without a previous 'if'
   36 |         else big.pb(tout[i]);
      |         ^~~~
stations.cpp:36:18: error: 'class std::vector<int>' has no member named 'pb'
   36 |         else big.pb(tout[i]);
      |                  ^~
stations.cpp:37:10: error: 'all' was not declared in this scope; did you mean 'atoll'?
   37 |     sort(all(big));
      |          ^~~
      |          atoll
stations.cpp:38:5: error: 'unq' was not declared in this scope
   38 |     unq(big);
      |     ^~~
stations.cpp:43:9: error: 'else' without a previous 'if'
   43 |         else {
      |         ^~~~
stations.cpp: In function 'int find_next_station(int, int, std::vector<int>)':
stations.cpp:51:10: error: 'all' was not declared in this scope; did you mean 'atoll'?
   51 |     sort(all(c));
      |          ^~~
      |          atoll
stations.cpp:57:9: error: 'sz' was not declared in this scope; did you mean 's'?
   57 |     if (sz(c)==1) return c.back();
      |         ^~
      |         s
stations.cpp:59:23: error: 'sz' was not declared in this scope; did you mean 's'?
   59 |         for(int i=0;i<sz(c);i++) {
      |                       ^~
      |                       s
stations.cpp:70:27: error: 'sz' was not declared in this scope; did you mean 's'?
   70 |             for(int i=0;i<sz(c);i++) {
      |                           ^~
      |                           s
stations.cpp:82:27: error: 'sz' was not declared in this scope; did you mean 's'?
   82 |             for(int i=0;i<sz(c);i++) {
      |                           ^~
      |                           s
stations.cpp:89:1: warning: control reaches end of non-void function [-Wreturn-type]
   89 | }
      | ^