Submission #309718

#TimeUsernameProblemLanguageResultExecution timeMemory
309718kris01Stations (IOI20_stations)C++14
100 / 100
977 ms1132 KiB
#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.clear();
	Tin.clear();
	Tout.clear();
	Depth.clear();
	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]) {
     if (t < s || c.size() == 1 || t > c[c.size() - 2])
            return c.back();
        return *lower_bound(c.begin(), c.end(), t);
	} else {
      auto it = upper_bound(c.begin(),c.end(),t);
      if (c.size() == 1 || t > s || t < c[1]) {
        return c[0];
      }
       return *(upper_bound(c.begin(), c.end(), t) - 1);
	}
}

Compilation message (stderr)

stations.cpp: In function 'int find_next_station(int, int, std::vector<int>)':
stations.cpp:61:12: warning: variable 'it' set but not used [-Wunused-but-set-variable]
   61 |       auto it = upper_bound(c.begin(),c.end(),t);
      |            ^~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...