답안 #400314

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
400314 2021-05-07T20:45:57 Z REALITYNB 기지국 (IOI20_stations) C++14
0 / 100
1234 ms 712 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-2;++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(1,-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&&u>=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; 
}

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++)
      |                     ~~~^~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Runtime error 1 ms 284 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 6 ms 328 KB Invalid labels (duplicates values). scenario=0, label=0
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 2 ms 704 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1234 ms 400 KB Output is correct
2 Runtime error 1 ms 292 KB Execution killed with signal 11
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 4 ms 712 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -