Submission #400321

# Submission time Handle Problem Language Result Execution time Memory
400321 2021-05-07T21:09:43 Z REALITYNB Stations (IOI20_stations) C++14
Compilation error
0 ms 0 KB
#include <bits/stdc++.h> 
using namespace std; 
vector<int> label(int n ,int l , vector<int> u , vector<int> v){
    vector<int> ans(n) ; 
    vector<int> adj[n] ; 
    for(int i=0;i<n-1;++i){
        adj[u[i]].push_back(v[i]); 
        adj[v[i]].push_back(u[i]); 
    }
    function<vector<int>(int,int,int)> dfs = [&](int a ,int p , int lvl){
        vector<int> ans ; 
        if(lvl)
            ans.push_back(a) ; 
        for(int x : adj[a]){
            if(x!=p){
                vector<int> res = dfs(x,a,lvl^1) ; 
                for(int x :res) ans.push_back(x) ;
            }
        }
        if(lvl==0) ans.push_back(a) ; 
        return ans ; 
    }; 
    vector<int> res  = dfs(0,-1,1) ; 
    for(int i=0;i<n;i++) ans[res[i]]=i ; 
    return ans ; 
}
int find_next_station(int u , int v , vector<int> ne){
    if(u==0){
        if(u<=v&&v<=ne[0]) return ne[0] ; 
        for(int i=1;i<ne.size();i++) if(ne[i]>=v&&v>ne[i-1]) return ne[i] ; 
    }
    if(u<=ne[0]){
        int dad = ne.back() ; 
        if(u<=v&&v<=ne[0]) return ne[0] ; 
        for(int i=1;i+1<ne.size();i++)
            if(ne[i]>=v&&v>ne[i-1]) return ne[i] ; 
        return dad ; 
    }
    else{
        int dad = ne[0] ;
        if(u>=v&&v>=ne.back()) return ne.back() ;  
        for(int i=(int)(ne.size()-2);i>0;i--)
            if(ne[i+1]>v&&v>=ne[i]) return ne[i] ; 
        return dad ; 
    }
    return 5/0; 
}
int main(){
    vector<int> res = label(4,5654,{0,0,0},{1,2,3}) ; 
    for(int x : res) cout << x << " "; 
        cout << endl ; 
    cout << find_next_station(1,2,{0}); 
}   

Compilation message

stations.cpp: In function 'int find_next_station(int, int, std::vector<int>)':
stations.cpp:30:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   30 |         for(int i=1;i<ne.size();i++) if(ne[i]>=v&&v>ne[i-1]) return ne[i] ;
      |                     ~^~~~~~~~~~
stations.cpp:35:24: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   35 |         for(int i=1;i+1<ne.size();i++)
      |                     ~~~^~~~~~~~~~
stations.cpp:46:13: warning: division by zero [-Wdiv-by-zero]
   46 |     return 5/0;
      |            ~^~
/tmp/ccZT2IlD.o: In function `main':
stub.cpp:(.text.startup+0x0): multiple definition of `main'
/tmp/ccZDWxxs.o:stations.cpp:(.text.startup+0x0): first defined here
collect2: error: ld returned 1 exit status