結果

問題 No.812 Change of Class
ユーザー lumc_lumc_
提出日時 2019-04-12 22:11:20
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 5,574 bytes
コンパイル時間 1,215 ms
コンパイル使用メモリ 124,240 KB
実行使用メモリ 14,516 KB
最終ジャッジ日時 2023-09-03 12:43:59
合計ジャッジ時間 5,514 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 34 ms
12,980 KB
testcase_01 AC 8 ms
5,740 KB
testcase_02 AC 19 ms
9,064 KB
testcase_03 AC 39 ms
14,516 KB
testcase_04 AC 35 ms
13,356 KB
testcase_05 AC 59 ms
11,828 KB
testcase_06 AC 50 ms
10,136 KB
testcase_07 AC 12 ms
5,692 KB
testcase_08 AC 6 ms
4,772 KB
testcase_09 AC 67 ms
12,588 KB
testcase_10 AC 68 ms
12,616 KB
testcase_11 AC 31 ms
8,456 KB
testcase_12 AC 55 ms
11,444 KB
testcase_13 AC 3 ms
4,652 KB
testcase_14 AC 3 ms
4,572 KB
testcase_15 AC 40 ms
9,680 KB
testcase_16 WA -
testcase_17 AC 44 ms
9,964 KB
testcase_18 AC 31 ms
8,588 KB
testcase_19 AC 37 ms
9,164 KB
testcase_20 AC 63 ms
12,480 KB
testcase_21 AC 30 ms
8,416 KB
testcase_22 AC 15 ms
6,372 KB
testcase_23 WA -
testcase_24 WA -
testcase_25 AC 12 ms
5,828 KB
testcase_26 AC 53 ms
10,712 KB
testcase_27 AC 46 ms
9,928 KB
testcase_28 AC 39 ms
9,184 KB
testcase_29 AC 9 ms
5,388 KB
testcase_30 AC 46 ms
9,756 KB
testcase_31 AC 37 ms
8,984 KB
testcase_32 AC 19 ms
6,660 KB
testcase_33 AC 49 ms
10,336 KB
testcase_34 AC 6 ms
4,984 KB
testcase_35 AC 12 ms
5,728 KB
testcase_36 AC 6 ms
4,948 KB
testcase_37 AC 20 ms
6,888 KB
testcase_38 AC 15 ms
6,104 KB
testcase_39 AC 20 ms
6,896 KB
testcase_40 AC 8 ms
5,252 KB
testcase_41 AC 13 ms
5,776 KB
testcase_42 AC 38 ms
9,148 KB
testcase_43 AC 28 ms
7,972 KB
testcase_44 AC 27 ms
7,956 KB
testcase_45 AC 5 ms
4,932 KB
testcase_46 AC 28 ms
7,848 KB
testcase_47 AC 27 ms
8,032 KB
testcase_48 AC 35 ms
8,776 KB
testcase_49 AC 10 ms
5,688 KB
testcase_50 AC 3 ms
4,732 KB
testcase_51 AC 14 ms
6,168 KB
testcase_52 AC 31 ms
8,164 KB
testcase_53 AC 7 ms
5,168 KB
testcase_54 AC 6 ms
5,120 KB
testcase_55 AC 22 ms
9,928 KB
testcase_56 AC 26 ms
11,248 KB
testcase_57 AC 28 ms
11,752 KB
testcase_58 AC 16 ms
8,156 KB
testcase_59 AC 31 ms
12,692 KB
testcase_60 AC 2 ms
4,576 KB
testcase_61 AC 2 ms
4,572 KB
testcase_62 AC 2 ms
4,840 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

// includes {{{
#include<iostream>
#include<iomanip>
#include<algorithm>
#include<vector>
#include<stack>
#include<queue>
#include<map>
#include<set>
#include<tuple>
#include<cmath>
#include<random>
#include<cassert>
#include<cstring>
// #include<deque>
// #include<multiset>
// #include<bitset>
// #include<cstring>
// #include<bits/stdc++.h>
// }}}
using namespace std;
using ll = long long;

// #undef DEBUG
// #define DEBUG
// DEBUG {{{
#include <array>
#include <deque>
#include <list>
#include <ostream>
#include <queue>
#include <stack>
#include <tuple>
#include <valarray>
#include <vector>
template < int n, class... T >
typename std::enable_if< (n >= sizeof...(T)) >::type __output_tuple(
    std::ostream &, std::tuple< T... > const &) {}
template < int n, class... T >
typename std::enable_if< (n < sizeof...(T)) >::type __output_tuple(
    std::ostream &os, std::tuple< T... > const &t) {
  os << (n == 0 ? "" : ", ") << std::get< n >(t);
  __output_tuple< n + 1 >(os, t);
}
template < class... T >
std::ostream &operator<<(std::ostream &os, std::tuple< T... > const &t) {
  os << "(";
  __output_tuple< 0 >(os, t);
  os << ")";
  return os;
}
template < class T, class U >
std::ostream &operator<<(std::ostream &os, std::pair< T, U > const &p) {
  os << "(" << p.first << ", " << p.second << ")";
  return os;
}
template < class T >
std::ostream &operator<<(std::ostream &os, const std::stack< T > &a) {
  os << "{";
  for(auto tmp = a; tmp.size(); tmp.pop())
    os << (a.size() == tmp.size() ? "" : ", ") << tmp.top();
  os << "}";
  return os;
}
template < class T, class Container, class Compare >
std::ostream &operator<<(std::ostream &os,
    std::priority_queue< T, Container, Compare > a) {
  os << "{ (top) ";
  while(a.size()) os << a.top() << (a.size() == 1 ? "" : ", "), a.pop();
  os << " }";
  return os;
}
template < class T, class Container >
std::ostream &operator<<(std::ostream &os, std::queue< T, Container > a) {
  os << "{ ";
  while(a.size()) os << a.front() << (a.size() == 1 ? "" : ", "), a.pop();
  os << " }";
  return os;
}
#ifdef DEBUG
#if !defined(DEBUG_OUT)
#define DEBUG_OUT std::cerr
#endif
#define dump(...)                                                                \
  [&]() {                                                                        \
    auto __debug_tap = std::make_tuple(__VA_ARGS__);                             \
    DEBUG_OUT << "[" << __LINE__ << "] " << #__VA_ARGS__ << " = " << __debug_tap \
    << std::endl;                                                      \
  }()
template < class T >
inline void dump2D(T &d, size_t sizey, size_t sizex) {
  for(size_t i = 0; i < sizey; i++) {
    DEBUG_OUT << "\t";
    for(size_t j = 0; j < sizex; j++)
      DEBUG_OUT << d[i][j] << (j + 1 == sizex ? "" : "\t");
    DEBUG_OUT << std::endl;
  }
}
template < class T >
inline void dump1D(T &d, size_t sizey) {
  for(size_t i = 0; i < sizey; i++) {
    DEBUG_OUT << d[i] << (i + 1 == sizey ? "" : " ");
  }
  DEBUG_OUT << std::endl;
}
template <
class T, class = typename std::iterator_traits< decltype(begin(T())) >::value_type,
      class = typename std::enable_if< !std::is_same< T, std::string >::value >::type >
      std::ostream &operator<<(std::ostream &os, const T &a) {
        os << "{";
        for(auto ite = begin(a); ite != end(a); ++ite)
          os << (ite == begin(a) ? "" : ", ") << *ite;
        os << "}";
        return os;
      }
#else
#define dump(...) (42)
#define dump2D(...) (42)
#define dump1D(...) (42)
template <
class T, class = typename std::iterator_traits< decltype(begin(T())) >::value_type,
      class = typename std::enable_if< !std::is_same< T, std::string >::value >::type >
      std::ostream &operator<<(std::ostream &os, const T &a) {
        for(auto ite = begin(a); ite != end(a); ++ite)
          os << (ite == begin(a) ? "" : " ") << *ite;
        return os;
      }
#endif
// }}}


int lg(int x) {
  int n = 0, t = 1;
  while(t < x) t <<= 1, n++;
  return n;
}

const int N = 1e5;
std::vector<std::vector<int>> g;
int n, m;

int used[N];

int dfs(int i) {
  if(used[i]) return 0;
  used[i] = 1;
  int res = 0;
  for(int j : g[i]) {
    res += dfs(j);
  }
  return res;
}

int dist[N][3];

void bfs(int f, int i, vector<int> & v) {
  queue<pair<int, int>> q;
  q.emplace(i, 0);
  dist[i][f] = 0;
  while(q.size()) {
    int i, d;
    tie(i, d) = q.front();
    dist[i][f] = d;
    v.emplace_back(i);
    q.pop();
    for(auto j : g[i]) {
      if(dist[j][f] == -1) {
        dist[j][f] = d + 1;
        q.emplace(j, d + 1);
      }
    }
  }
}

int main() {
  std::ios::sync_with_stdio(false), std::cin.tie(0);
  cin >> n >> m;
  g.resize(n);
  for(int i = 0; i < m; i++) {
    int a, b; std::cin >> a >> b;
    a--; b--;
    g[a].emplace_back(b);
    g[b].emplace_back(a);
  }
  for(int i = 0; i < n; i++) if(!used[i]) dfs(i);
  memset(dist, -1, sizeof dist);
  vector<int> ans1(n);
  vector<int> ans2(n);
  dump(n, m);
  for(int i = 0; i < n; i++) if(dist[i][0] == -1) {
    vector<int> v;
    bfs(0, i, v);
    pair<int, int> best(-1, 0);
    for(auto e : v) {
      ans1[e] = v.size() - 1;
      best = max(best, make_pair(dist[e][0], e));
    }
    v.clear();
    bfs(1, best.second, v);
    best = pair<int, int>(-1, 0);
    for(auto e : v) {
      best = max(best, make_pair(dist[e][1], e));
    }
    bfs(2, best.second, v);
    for(auto e : v) {
      ans2[e] = max(lg(max(dist[e][1], dist[e][2])), 0);
    }
  }

  int q;
  cin >> q;
  while(q--) {
    int a;
    cin >> a; a--;
    cout << ans1[a] << " " << ans2[a] << "\n";
  }

  return 0;
}
0