답안 #419143

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
419143 2021-06-06T13:27:44 Z NintsiChkhaidze 기지국 (IOI20_stations) C++14
0 / 100
914 ms 752 KB
#include "stations.h"
#include <bits/stdc++.h>
//#include <iostream>
//#include <vector>
#define pb push_back
using namespace std;
vector <int> vec[1005];
int dp[1005],d[23][1005];
void dfs(int x,int p){
    d[0][x] = p;
    dp[x] = dp[p] + 1;
    for (int j=0;j<vec[x].size();j++){
        int to = vec[x][j];
        if (to == p) continue;
        dfs(to,x);
    }
}
 
vector<int> label(int n, int k, vector<int> u, vector<int> v) {
    vector<int> labels;
    
    for (int i=0;i<1001;i++){
        vec[i].clear();
        dp[i] = 0;
    }
    for (int i=0;i<u.size();i++){
        vec[u[i]].pb(v[i]);
        vec[v[i]].pb(u[i]);
    }
    
    dfs(0,0);
    for (int i=0;i<n;i++)
        for (int j = 1; j <= 18; j++)
            d[j][i] = d[j - 1][d[j - 1][i]];
        
    for (int i=0;i<n;i++)
        labels.pb(i);
 
    return labels;
}
int lca(int x,int y){
    for (int j = 18; j>= 0;j--)
        if (dp[d[j][x]] >= dp[y]) x = d[j][x];
    
    if (x == y) return x;
    for (int j = 18; j>=0;j--)
        if (d[j][x] != d[j][y]) x = d[j][x],y = d[j][y];
        
    return d[0][x];
}
int dis(int x,int y){
    if (dp[x] < dp[y]) swap(x,y);
    int c = lca(x,y);
    //cout<<x<<" ^^ "<<y<<" lca = "<<c<<endl;
    return dp[x] +dp[y] - 2*dp[c];
}
int find_next_station(int s, int t, vector<int> c) {
    int D = dis(s,t),ans=-1;
    for (int i=0;i<c.size();i++){
        int DD = dis(c[i],t);
      //  cout<<"DD == "<<DD<<" "<<c[i]<<" ^ "<<t<<endl;
        if (DD < D) ans = c[i];
    }
    //cout<<"ans = "<<ans<<endl;
    return ans;
}

Compilation message

stations.cpp: In function 'void dfs(int, int)':
stations.cpp:12:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   12 |     for (int j=0;j<vec[x].size();j++){
      |                  ~^~~~~~~~~~~~~~
stations.cpp: In function 'std::vector<int> label(int, int, std::vector<int>, std::vector<int>)':
stations.cpp:26:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   26 |     for (int i=0;i<u.size();i++){
      |                  ~^~~~~~~~~
stations.cpp: In function 'int find_next_station(int, int, std::vector<int>)':
stations.cpp:59:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   59 |     for (int i=0;i<c.size();i++){
      |                  ~^~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Incorrect 616 ms 752 KB Wrong query response.
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 576 ms 628 KB Wrong query response.
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 639 ms 656 KB Wrong query response.
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 914 ms 520 KB Wrong query response.
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 663 ms 744 KB Wrong query response.
2 Halted 0 ms 0 KB -