Submission #309710

# Submission time Handle Problem Language Result Execution time Memory
309710 2020-10-04T11:12:39 Z kris01 Stations (IOI20_stations) C++14
0 / 100
3000 ms 2097156 KB
#include "stations.h"
#include <bits/stdc++.h>
#define pii pair <int,int>
#define mp make_pair
using namespace std;
vector < vector <int> > Adj; // Adjacency List for the graph
vector <int> Tin,Tout; // Entry and Exit times respectively
vector <int> Depth; // Depth of a given node from the root (node 1)
int timer = 0;

void DFS(int v,int p) {
    Tin[v] = timer++;
    for (int x : Adj[v]) {
     if (x == p) continue;
     Depth[x] = Depth[v] + 1;
     DFS(x,v);
    }
    Tout[v] = timer++;
}

std::vector<int> label(int n, int k, std::vector<int> u, std::vector<int> v) {
	std::vector<int> labels(n);
	Adj.resize(n);
	Tin.resize(n);
	Tout.resize(n);
	Depth.resize(n+1,0);
	for (int i = 0;i < n-1;i++) {
        int a = u[i];
        int b = v[i];
        Adj[a].push_back(b);
        Adj[b].push_back(a);
	}
    timer = 0;
    DFS(0,-1);
    vector <pair <int,int> > LBLS(n); // Dummy vector to sort the labels
    for (int i = 0;i < n;i++) {
        if (Depth[i] % 2 == 0) {
         LBLS[i] = mp(Tin[i],i);
        } else {
         LBLS[i] = mp(Tout[i],i);
        }
    }
    sort(LBLS.begin(),LBLS.end());
    for (int i = 0;i < n;i++) {
     labels[LBLS[i].second] = i;
    }
	return labels;
}

int find_next_station(int s, int t, std::vector<int> c) {
	sort(c.begin(),c.end());
	if (s < c[0]) {
     auto it = lower_bound(c.begin(),c.end(),t);
     if (c.size() == 1 || it == c.end()) {
        return c.back();
     }
     return *it;
	} else {
      auto it = upper_bound(c.begin(),c.end(),t);
      if (c.size() == 1 || t > s) {
        return c[0];
      }
        it--;
        return *it;
	}
}
# Verdict Execution time Memory Grader output
1 Runtime error 1 ms 376 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 3040 ms 1912 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 1718 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 Correct 1012 ms 648 KB Output is correct
2 Runtime error 1394 ms 2097156 KB Execution killed with signal 9 (could be triggered by violating memory limits)
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 2926 ms 2097156 KB Execution killed with signal 9 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -