제출 #732171

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

vector<int> adj[1001],A;
int ans[1001],cnt;

void dfs(int x, int par, int level) {
    if (level%2==0) ans[x]=++cnt;
    for (auto s : adj[x]) {
        if (s!=par) dfs(s,x,level+1);
    }
    if (level%2==1) ans[x]=++cnt;
}

vector<int> label(int n, int k, vector<int> u, vector<int> v) {
    cnt=0;
  	A.clear();
    for (int i=0; i<n; ++i) adj[i].clear();

    for (int i=0; i<n-1; ++i) {
        adj[u[i]].push_back(v[i]);
        adj[v[i]].push_back(u[i]);
    }
    dfs(0,0,0);
    for (int i=0; i<n; ++i) A.push_back(ans[i]);
    return A;
}

int find_next_station(int s, int t, vector<int> c) {
    if (s==1) {
        int ans;
        for (int i=c.size()-1; i>=0; --i) if (t<=c[i]) ans=i;
        return ans;
    }

    if (s>c[0]) {
        if (c.size()==1) return c[0];
        if (t<c[1] || t>s) return c[0];

        int ans;
        for (int i=1; i<c.size(); ++i) if (t>=c[i]) ans=i;
        return ans;

    } else {
        if (c.size()==1) return c[0];
        if (t<s || t>c[c.size()-2]) return c.back();

        int ans;
        for (int i=c.size()-2; i>=0; --i) if (t<=c[i]) ans=i;
        return ans;
    }
}

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

stations.cpp: In function 'int find_next_station(int, int, std::vector<int>)':
stations.cpp:43:24: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   43 |         for (int i=1; i<c.size(); ++i) if (t>=c[i]) ans=i;
      |                       ~^~~~~~~~~
stations.cpp:50:13: warning: 'ans' may be used uninitialized in this function [-Wmaybe-uninitialized]
   50 |         int ans;
      |             ^~~
/usr/bin/ld: /tmp/ccyD6dCU.o: in function `main':
stub.cpp:(.text.startup+0x0): multiple definition of `main'; /tmp/ccSi81LR.o:stations.cpp:(.text.startup+0x0): first defined here
collect2: error: ld returned 1 exit status