Submission #419142

# Submission time Handle Problem Language Result Execution time Memory
419142 2021-06-06T13:27:03 Z NintsiChkhaidze Stations (IOI20_stations) C++14
Compilation error
0 ms 0 KB
#include "stations.h"
#nclude <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:2:2: error: invalid preprocessing directive #nclude; did you mean #include?
    2 | #nclude <bits/stdc++.h>
      |  ^~~~~~
      |  include
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++){
      |                  ~^~~~~~~~~