답안 #35886

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
35886 2017-12-02T03:07:53 Z funcsr Mousetrap (CEOI17_mousetrap) C++14
컴파일 오류
0 ms 0 KB
#include <iostream>
#include <vector>
#define pb push_back
#define all(xs) xs.begin(), xs.end()
#define rep(i, n) for (int i=0; i<(n); i++)
using namespace std;

int N, T, M;
vector<int> G[1000000];
int dp[1000000];
bool sub[1000000];

void dfs(int x, int p) {
  vector<int> values;
  int ctr = 0, ti = -1;
  sub[x] = x == M;
  for (int t : G[x]) {
    if (t == p) continue;
    dfs(t, x);
    sub[x] |= sub[t];
    if (sub[t]) ti = t;
    values.pb(dp[t]);
    ctr++;
  }
  if (ti != -1) {
    dp[x] = (ctr-1) + dp[ti];
    return;
  }
  sort(all(values), greater<int>());
  if (values.size() >= 2) ctr += values[1];
  dp[x] = ctr;
}

signed main() {
  cin >> N >> T >> M;
  T--, M--;
  rep(i, N-1) {
    int u, v;
    cin >> u >> v;
    u--, v--;
    G[u].pb(v);
    G[v].pb(u);
  }
  dfs(T, -1);
  cout << dp[T] << "\n";
  return 0;
}

Compilation message

mousetrap.cpp: In function 'void dfs(int, int)':
mousetrap.cpp:29:35: error: 'sort' was not declared in this scope
   sort(all(values), greater<int>());
                                   ^