Submission #1296333

#TimeUsernameProblemLanguageResultExecution timeMemory
1296333eri16Stations (IOI20_stations)C++20
Compilation error
0 ms0 KiB
#include "stations.h"
#include <bits/stdc++.h>

using namespace std;

vector<int> lbl(n);

void dfs(int n, vector<vector<int>>& adj, int& depth) {

    int in,ot;
    
    in=depth;
    depth++;
    
    for (int i=0; i<adj[n].size(); i++){
        dfs(adj[n][i],adj,depth);
    }
    ot=depth;
    depth++;
    lbl[n]=in*1000+ot;

}

vector<int> label(int n, int k, vector<int> u, vector<int> v) {

	vector<vector<int>> adj(n+1);
	for(int i=0; i<n-1; i++) {
		adj[u[i]].push_back(v[i]);
		adj[v[i]].push_back(u[i]);
	}

    dfs(0,adj,0);
    return lbl;
}

int find_next_station(int s, int t, vector <int> cp){

    int parent=-1;
    
    int in=s/1000;
    int ot=s%1000;
    
    for (int i=0; i<cp.size(); i++){
        
        int k1,k2;
        
        k1=cp[i]/1000;
        k2=cp[i]%1000;
        
        if (k1<=in && ot<=k2){
            parent=i;
        }
    }

    int ins=t/1000;
    int ots=t%1000;

    for (int i=0; i<cp.size() && i!=parent; i++){
        int k1,k2;
        
        k1=cp[i]/1000;
        k2=cp[i]%1000;
        
        if (ins>=k1 && k2<=ots){
            return cp[i];
        }
    }
    
    return cp[parent];
    
}

Compilation message (stderr)

stations.cpp:6:17: error: 'n' was not declared in this scope; did you mean 'yn'?
    6 | vector<int> lbl(n);
      |                 ^
      |                 yn
stations.cpp: In function 'std::vector<int> label(int, int, std::vector<int>, std::vector<int>)':
stations.cpp:32:15: error: cannot bind non-const lvalue reference of type 'int&' to an rvalue of type 'int'
   32 |     dfs(0,adj,0);
      |               ^
stations.cpp:8:48: note:   initializing argument 3 of 'void dfs(int, std::vector<std::vector<int> >&, int&)'
    8 | void dfs(int n, vector<vector<int>>& adj, int& depth) {
      |                                           ~~~~~^~~~~