답안 #313447

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
313447 2020-10-16T02:58:40 Z qiangbao 기지국 (IOI20_stations) C++14
0 / 100
1380 ms 2097156 KB
#include <iostream>
#include <algorithm>
#include <vector>

#define pb push_back

using namespace std;

typedef pair<int, int> pii;

vector<int> con[1001];
vector<int> son[1001];
bool used[1001];

vector<int> ans;

void rt(int x)
{
    int i;
    
    for(i=0;i<con[x].size();i++){
        int f=con[x][i];
        if(!used[f])
            son[x].pb(f), used[f]=true, rt(f);
    }
}

pii wk(int x, int lev, int label)
{
    pii ret={label, 1};
    int i;
    
    if(lev%2==0){
        ans[x]=label;
        for(i=0;i<son[x].size();i++){
            pii f=wk(son[x][i], lev+1, label+1);
            label+=f.second;
            ret.first=max(ret.first, f.first);
            ret.second+=f.second;
        }
    }
    if(lev%2==1){
        for(i=0;i<son[x].size();i++){
            pii f=wk(son[x][i], lev+1, label);
            label+=f.second;
            ret.first=max(ret.first, f.first);
            ret.second+=f.second;
        }
        ans[x]=label;
    }
    
    return ret;
}

vector<int> label(int n, int k, vector<int> u, vector<int> v)
{
    int i;
    for(i=0;i<=1000;i++){
        con[i].clear();
        son[i].clear();
        used[i]=false;
    }
    
    for(i=0;i<n;i++){
        con[u[i]].pb(v[i]);
        con[v[i]].pb(u[i]);
        ans.pb(0);
    }
    rt(0);
    wk(0, 1, 1);
    
    return ans;
}

int find_next_station(int s, int t, vector<int> nei)
{
    int lev=1;
    int i;
    
    for(i=0;i<nei.size();i++)
        if(nei[i]<s)
            lev=0;
    
    if(lev==1){
        sort(nei.begin(), nei.end());
        bool maxi=false;
        if(t<s)
            maxi=true;
        if(maxi)
            return nei[nei.size()-1];
        for(i=int(nei.size())-1;i>=0;i--)
            if(t>nei[i])
                return nei[i];
    }
    else{
        sort(nei.begin(), nei.end());
        bool mini=false;
        if(t>=nei[nei.size()-1])
            mini=true;
        if(mini)
            return nei[0];
        for(i=0;i<nei.size();i++)
            if(t<nei[i])
                return nei[i];
    }
    
    return -1;
}

Compilation message

stations.cpp: In function 'void rt(int)':
stations.cpp:21:14: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   21 |     for(i=0;i<con[x].size();i++){
      |             ~^~~~~~~~~~~~~~
stations.cpp: In function 'pii wk(int, int, int)':
stations.cpp:35:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   35 |         for(i=0;i<son[x].size();i++){
      |                 ~^~~~~~~~~~~~~~
stations.cpp:43:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   43 |         for(i=0;i<son[x].size();i++){
      |                 ~^~~~~~~~~~~~~~
stations.cpp: In function 'int find_next_station(int, int, std::vector<int>)':
stations.cpp:80:14: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   80 |     for(i=0;i<nei.size();i++)
      |             ~^~~~~~~~~~~
stations.cpp:102:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  102 |         for(i=0;i<nei.size();i++)
      |                 ~^~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Runtime error 1380 ms 2097152 KB Execution killed with signal 9 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 1225 ms 2097156 KB Execution killed with signal 9 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 1213 ms 2097152 KB Execution killed with signal 9 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 1242 ms 2097156 KB Execution killed with signal 9 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 1219 ms 2097156 KB Execution killed with signal 9 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -