Submission #697064

#TimeUsernameProblemLanguageResultExecution timeMemory
697064garam1732Stations (IOI20_stations)C++14
100 / 100
946 ms916 KiB
#include "stations.h"
#include <bits/stdc++.h>
using namespace std;

typedef pair<int, int> pi;

vector<int> adj[1010];
int in[1010], out[1010], cnt;

void dfs(int here, int par, bool flag, vector<int>& labels) {
    in[here] = cnt++;
    for(int there : adj[here]) {
        if(there == par) continue;
        dfs(there, here, !flag, labels);
    }
    out[here] = cnt++;

    labels[here] = (flag ? in[here] : out[here]);
}

std::vector<int> label(int n, int k, std::vector<int> u, std::vector<int> v) {
	std::vector<int> labels(n);
	for(int i = 0; i < n; i++) adj[i].clear();
	cnt = 0;

	for(int i = 0; i < u.size(); i++) {
        adj[u[i]].push_back(v[i]);
        adj[v[i]].push_back(u[i]);
	}

	dfs(0, 0, 0, labels);

	priority_queue<pi> pq;
	for(int i = 0; i < n; i++) pq.push(pi(labels[i], i));
	for(int i = n-1; i >= 0; i--) {
        labels[pq.top().second] = i;
        pq.pop();
	}

	return labels;
}

int find_next_station(int s, int t, std::vector<int> c) {
	if(s < c[0]) {
        if(s < t && t <= c[0]) return c[0];
        for(int i = 1; i < c.size(); i++) if(c[i-1] < t && t <= c[i]) return c[i];
        return *c.rbegin();
	}

	for(int i = 2; i < c.size(); i++) if(c[i-1] <= t && t < c[i]) return c[i-1];
	if(*c.rbegin() <= t && t < s) return *c.rbegin();
	return c[0];
}

Compilation message (stderr)

stations.cpp: In function 'std::vector<int> label(int, int, std::vector<int>, std::vector<int>)':
stations.cpp:26:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   26 |  for(int i = 0; i < u.size(); i++) {
      |                 ~~^~~~~~~~~~
stations.cpp: In function 'int find_next_station(int, int, std::vector<int>)':
stations.cpp:46:26: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   46 |         for(int i = 1; i < c.size(); i++) if(c[i-1] < t && t <= c[i]) return c[i];
      |                        ~~^~~~~~~~~~
stations.cpp:50:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   50 |  for(int i = 2; i < c.size(); i++) if(c[i-1] <= t && t < c[i]) return c[i-1];
      |                 ~~^~~~~~~~~~
#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...