제출 #605335

#제출 시각아이디문제언어결과실행 시간메모리
605335Sam_a17기지국 (IOI20_stations)C++14
52.32 / 100
1049 ms832 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];

vector<int> label(int n, int k, vector<int> u, vector<int> v) {
	vector<int> labels(n), in(n);
  vector<int> adj[n + 1];

  int timer = 0;
  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] * 1000 + tout[i];
    tin[i] = tout[i] = 0;
    adj[i].clear();
	}
 
	return labels;
}
 
int find_next_station(int s, int t, std::vector<int> c) {
  int s_tu = s % 1000, s_ti = s / 1000;
  int t_tu = t % 1000, t_ti = t / 1000;

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

      if(t_ti >= new_ti && t_tu <= new_tu) {
        return i;
      }
    }

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

    assert(false);
  }

	return c[0];
}

컴파일 시 표준 에러 (stderr) 메시지

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