Submission #1298637

#TimeUsernameProblemLanguageResultExecution timeMemory
1298637lukaye_19Stations (IOI20_stations)C++20
Compilation error
0 ms0 KiB
#include "stations.h"
#include <bits/stdc++.h>
using namespace std;

int t = 0;

vector<vector<int>>adj;
vector<int>labels;

void DFS(int node,int parent,int odd)
{
    if (odd) labels[node] = t++;

    for (int child : adj[node]) {
        if (child != parent) DFS(child,node,1 - odd);
    }
    
    if (!odd) labels[node] = t++;
}

vector<int> label(int n, int k, vector<int> u, vector<int> v)
{
    adj.assign(n, {});
    labels.assign(n, 0);

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

    t = 0;
    
    DFS(0, -1, 1);

    return labels;
}

int find_next_station(int s,int t,vector<int> c)
{
    #include "stations.h"
#include <bits/stdc++.h>
using namespace std;

int t = 0;

vector<vector<int>>adj;
vector<int>labels;

void DFS(int node,int parent,int odd)
{
    if (odd) labels[node] = t++;

    for (int child : adj[node]) {
        if (child != parent) DFS(child,node,1 - odd);
    }
    
    if (!odd) labels[node] = t++;
}

vector<int> label(int n, int k, vector<int> u, vector<int> v)
{
    adj.assign(n,{});
    labels.assign(n,0);

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

    t = 0;
    
    DFS(0,-1,1);

    return labels;
}

int find_next_station(int s,int ta,vector<int> c)
{
    sort(c.begin(),c.end());

    if (s < c[0]) {
        if (ta <= s) return c[c.size() - 1];

        for (int i = 0; i < c.size(); i++) 
        {
            if (ta <= c[i]) return c[i];
        }
        
        return c[n - 1];
    } 
    else 
    {
        if (ta >= s) return c[0];

        for (int i = c.size() - 1; i >= 0; i--) 
        {
            if (ta >= c[i]) return c[i];
        }
        
        return c[0];
    }
}

Compilation message (stderr)

stations.cpp: In function 'int find_next_station(int, int, std::vector<int>)':
stations.cpp:48:5: error: declaration of 'int t' shadows a parameter
   48 | int t = 0;
      |     ^
stations.cpp:42:33: note: 'int t' previously declared here
   42 | int find_next_station(int s,int t,vector<int> c)
      |                             ~~~~^
stations.cpp:54:1: error: a function-definition is not allowed here before '{' token
   54 | {
      | ^
stations.cpp:65:1: error: a function-definition is not allowed here before '{' token
   65 | {
      | ^
stations.cpp:86:1: error: a function-definition is not allowed here before '{' token
   86 | {
      | ^
stations.cpp:110:2: error: expected '}' at end of input
  110 | }
      |  ^
stations.cpp:43:1: note: to match this '{'
   43 | {
      | ^
stations.cpp:110:2: warning: no return statement in function returning non-void [-Wreturn-type]
  110 | }
      |  ^