Submission #605258

#TimeUsernameProblemLanguageResultExecution timeMemory
605258Sam_a17Stations (IOI20_stations)C++14
0 / 100
836 ms636 KiB
#include <bits/stdc++.h>
using namespace std;
 
#define sz(x) (int((x).size()))
#define len(x) (int)x.length()
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define dbg(x) cout << #x << " " << x << endl;
#define uniq(x) x.resize(unique(all(x)) - x.begin());
 
#define pb push_back
#define ld long double
#define ll long long
 
void pr(vector<int>& a) {
  cerr << "arr" << " ";
  for(auto i: a) {
    cerr << i << " "; 
  } cerr << endl;
}

const int N = 2e5 + 10;
int tin[N], tout[N], timer;
 
vector<int> label(int n, int k, vector<int> u, vector<int> v) {
	vector<int> labels(n), in(n);
  vector<int> adj[n + 1];

  for(int i = 0; i < n - 1; i++) {
    in[u[i]]++, in[v[i]]++;
    adj[u[i]].push_back(v[i]);
    adj[v[i]].push_back(u[i]);
  }
 
  function<void(int node, int parent)> dfs;

  dfs = [&](int node, int parent) {
    tin[node] = timer++;
    for(auto i: adj[node]) {
      if(i == parent) continue;
      dfs(i, node);
    }
    tout[node] = timer - 1;
  };

  dfs(0, -1);

	for (int i = 0; i < n; i++) {
		labels[i] = tin[i] * 10000 + tout[i];
    adj[i].clear(), timer = 0;
    tin[i] = tout[i] = 0;
	}
 
	return labels;
}
 
int find_next_station(int s, int t, std::vector<int> c) {
  int s_ti = s % 10000, s_tu = s / 10000;
  int t_ti = t % 10000, t_tu = t / 10000;

  if(t_ti >= s_ti && t_tu <= s_tu) {
    // t's subtree
    for(auto i: c) {
      int new_ti = i % 10000, new_tu = i / 10000;
      if(t_ti >= new_ti && t_tu <= new_tu) {
        return i;
      }
    }

    // assert(false);
  } else {
    for(auto i: c) {
      int new_ti = i % 10000, new_tu = i / 10000;
      if(new_ti < s_ti) {
        return i;
      }
    }
    // assert(false);
  }

	return c[0];
}

Compilation message (stderr)

stations.cpp: In function 'int find_next_station(int, int, std::vector<int>)':
stations.cpp:73:31: warning: unused variable 'new_tu' [-Wunused-variable]
   73 |       int new_ti = i % 10000, new_tu = i / 10000;
      |                               ^~~~~~
#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...