Submission #1298123

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

int t = 1;

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)
{
    vector<vector<int>>adjc(n);
    vector<int>labelsc(n);
    
    adj.clear();
    labels.clear();
    
    adj = adjc;
    labels = labelsc;
      
    for (int i = 0; i < n - 1; i++)
    {
        adj[u[i] - 1].push_back(v[i] - 1);
        adj[v[i] - 1].push_back(u[i] - 1);
    }

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

    return labels;
}

int find_next_station(int s,int t,vector<int>c)
{
    sort(c.begin(),c.end());
    
    // find if im odd or even 
    
    int next = -1;
    
    for (int i = 0; i < c.size(); i++)
    {
        if (c[i] < t)
        {
            next = c[i];
        }
    }
    
    if (next == -1) return c[0];
    
    return next;
}

int main(){
    int n = 13;
    int k = 14;
    vector<int>u = {1,1,1,7,7,6,6,13,13,13,11,11};
    vector<int>v = {2,7,13,6,3,4,5,8,9,11,10,12};
    
    vector<int>vv= label(n,k,u,v);
    
    for (int i = 0; i < vv.size(); i++)
    {
        cout << vv[i] << ' ';
    }cout<<"\n";

    vv=label(n,k,u,v);
    
    for (int i = 0; i < vv.size(); i++)
    {
        cout << vv[i] << ' ';
    }cout<<"\n";
    

    cout << endl;
    
    vector <int> options = {4,5,7};
    
    int answer = find_next_station(3,2,options);    cout << answer << endl;
    answer = find_next_station(1,3,options);    cout << answer << endl;
    answer = find_next_station(1,3,options);
    
    cout << answer << endl;
}

Compilation message (stderr)

/usr/bin/ld: /tmp/ccfgf7xU.o: in function `main':
stub.cpp:(.text.startup+0x0): multiple definition of `main'; /tmp/cck8ACr5.o:stations.cpp:(.text.startup+0x0): first defined here
collect2: error: ld returned 1 exit status