Submission #395983

# Submission time Handle Problem Language Result Execution time Memory
395983 2021-04-29T10:00:53 Z benedict0724 Stations (IOI20_stations) C++17
0 / 100
3000 ms 2097156 KB
#include "stations.h"
#include <vector>
#include <algorithm>

using namespace std;
vector<int> adj[1000];
vector<int> labels;
int sub[1000];

void dfs1(int x, int p)
{
    sub[x] = 1;
    for(int i : adj[x])
    {
        if(i == p) continue;
        dfs1(i, x);
        sub[x] += sub[i];
    }
}

void dfs2(int x, int p, int d, int l, int r){
    if(p != -1 && d == 0) labels[x] = l;
    else if(p != -1) labels[x] = r;

    int tmp = l;
    if(d == 0) tmp++;
    for(int i : adj[x])
    {
        if(i == p) continue;
        dfs2(i, x, !d, tmp, tmp + sub[i] - 1);
        tmp += sub[i];
    }
}

vector<int> label(int n, int k, vector<int> u, vector<int> v) {
    labels.resize(n);
	for(int i=0;i<n-1;i++){
        adj[u[i]].push_back(v[i]);
        adj[v[i]].push_back(u[i]);
	}
	dfs1(0, -1);
	labels[0] = 0;
	dfs2(0, -1, 0, 0, n-1);
	return labels;
}

int find_next_station(int s, int t, std::vector<int> c) {
    int n = c.size() - 1;
    int m = c[0], M = c[n];

    if(m > s)
    {
        if(t < s || t > M) return M;
        for(int i=0;i<=n;i++)
        {
            if(t <= c[i]) return c[i];
        }
    }

    if(t > s || t < m) return m;
    for(int i=n;i>=0;i--)
    {
            if(t >= c[i]) return c[i];
    }

    return c[0];
}
# Verdict Execution time Memory Grader output
1 Runtime error 1250 ms 2097156 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 3062 ms 320 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 1334 ms 2097156 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1001 ms 504 KB Output is correct
2 Runtime error 1045 ms 2097156 KB Execution killed with signal 9
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 2183 ms 2097156 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -