Submission #319154

# Submission time Handle Problem Language Result Execution time Memory
319154 2020-11-04T09:22:15 Z alextodoran Stations (IOI20_stations) C++17
0 / 100
1272 ms 2097156 KB
/**
 ____ ____ ____ ____ ____
||a |||t |||o |||d |||o ||
||__|||__|||__|||__|||__||
|/__\|/__\|/__\|/__\|/__\|

**/

#include <bits/stdc++.h>
#include "stations.h"

using namespace std;

const int N_MAX = 1002;

vector <int> edges[N_MAX];

int minLabel[N_MAX], maxLabel[N_MAX];

int curr;

int depth[N_MAX];

void dfs (int u, int parent = -1)
{
    minLabel[u] = maxLabel[u] = curr++;
    for(int v : edges[u])
        if(v != parent)
        {
            depth[v] = depth[u] + 1;
            dfs(v);
            maxLabel[u] = max(maxLabel[u], maxLabel[v]);
        }
}

vector <int> label (int n, int k, vector <int> u, vector <int> v)
{
    for(int i = 1; i < n; i++)
    {
        int a = u[i - 1];
        int b = v[i - 1];
        edges[a].push_back(b);
        edges[b].push_back(a);
    }
    dfs(1);
	vector <int> labels(n);
    for(int i = 1; i <= n; i++)
        if(depth[i] & 1)
            labels[i - 1] = minLabel[i];
        else
            labels[i - 1] = maxLabel[i];
	return labels;
}

int find_next_station (int s, int t, vector <int> c)
{
    bool odd = true;
    for(int u : c)
        odd &= (u < s);
    int minL, maxL;
    if(odd == true)
    {
        minL = s;
        sort(c.begin(), c.end());
        if((int)c.size() == 1)
            maxL = minL;
        else
            maxL = c.end()[-2];
        if(minL <= t && t <= maxL)
        {
            for(int u : c)
                if(t <= u)
                    return u;
        }
        else
            return c.back();
    }
    else
    {
        maxL = s;
        sort(c.begin(), c.end());
        reverse(c.begin(), c.end());
        if((int)c.size() == 1)
            minL = maxL;
        else
            minL = c.end()[-2] - 1;
        if(minL <= t && t <= maxL)
        {
            for(int u : c)
                if(u <= t)
                    return u;
        }
        else
            return c.back();
    }
}

Compilation message

stations.cpp: In function 'std::vector<int> label(int, int, std::vector<int>, std::vector<int>)':
stations.cpp:47:5: warning: this 'for' clause does not guard... [-Wmisleading-indentation]
   47 |     for(int i = 1; i <= n; i++)
      |     ^~~
stations.cpp:52:2: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'for'
   52 |  return labels;
      |  ^~~~~~
stations.cpp: In function 'int find_next_station(int, int, std::vector<int>)':
stations.cpp:96:1: warning: control reaches end of non-void function [-Wreturn-type]
   96 | }
      | ^
# Verdict Execution time Memory Grader output
1 Runtime error 1272 ms 2097156 KB Execution killed with signal 9 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 1260 ms 2097156 KB Execution killed with signal 9 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 1237 ms 2097156 KB Execution killed with signal 9 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 1249 ms 2097156 KB Execution killed with signal 9 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 1241 ms 2097152 KB Execution killed with signal 9 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -