結果

問題 No.1254 補強への架け橋
ユーザー keijakkeijak
提出日時 2020-11-16 07:08:57
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 261 ms / 2,000 ms
コード長 4,837 bytes
コンパイル時間 3,041 ms
コンパイル使用メモリ 221,772 KB
実行使用メモリ 43,692 KB
最終ジャッジ日時 2023-09-30 07:12:16
合計ジャッジ時間 17,089 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 1 ms
4,380 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 1 ms
4,376 KB
testcase_07 AC 2 ms
4,376 KB
testcase_08 AC 1 ms
4,376 KB
testcase_09 AC 2 ms
4,376 KB
testcase_10 AC 1 ms
4,376 KB
testcase_11 AC 1 ms
4,376 KB
testcase_12 AC 1 ms
4,380 KB
testcase_13 AC 1 ms
4,380 KB
testcase_14 AC 1 ms
4,380 KB
testcase_15 AC 2 ms
4,376 KB
testcase_16 AC 1 ms
4,380 KB
testcase_17 AC 1 ms
4,380 KB
testcase_18 AC 2 ms
4,380 KB
testcase_19 AC 1 ms
4,376 KB
testcase_20 AC 1 ms
4,380 KB
testcase_21 AC 1 ms
4,376 KB
testcase_22 AC 2 ms
4,376 KB
testcase_23 AC 1 ms
4,376 KB
testcase_24 AC 1 ms
4,376 KB
testcase_25 AC 1 ms
4,376 KB
testcase_26 AC 2 ms
4,376 KB
testcase_27 AC 1 ms
4,376 KB
testcase_28 AC 1 ms
4,384 KB
testcase_29 AC 1 ms
4,380 KB
testcase_30 AC 1 ms
4,376 KB
testcase_31 AC 2 ms
4,376 KB
testcase_32 AC 2 ms
4,380 KB
testcase_33 AC 1 ms
4,380 KB
testcase_34 AC 1 ms
4,380 KB
testcase_35 AC 1 ms
4,376 KB
testcase_36 AC 1 ms
4,376 KB
testcase_37 AC 1 ms
4,376 KB
testcase_38 AC 1 ms
4,376 KB
testcase_39 AC 1 ms
4,376 KB
testcase_40 AC 1 ms
4,376 KB
testcase_41 AC 1 ms
4,376 KB
testcase_42 AC 1 ms
4,376 KB
testcase_43 AC 2 ms
4,376 KB
testcase_44 AC 2 ms
4,376 KB
testcase_45 AC 2 ms
4,376 KB
testcase_46 AC 2 ms
4,376 KB
testcase_47 AC 2 ms
4,376 KB
testcase_48 AC 2 ms
4,380 KB
testcase_49 AC 2 ms
4,376 KB
testcase_50 AC 2 ms
4,380 KB
testcase_51 AC 2 ms
4,380 KB
testcase_52 AC 2 ms
4,376 KB
testcase_53 AC 2 ms
4,380 KB
testcase_54 AC 2 ms
4,376 KB
testcase_55 AC 2 ms
4,380 KB
testcase_56 AC 1 ms
4,376 KB
testcase_57 AC 2 ms
4,380 KB
testcase_58 AC 2 ms
4,380 KB
testcase_59 AC 1 ms
4,380 KB
testcase_60 AC 2 ms
4,376 KB
testcase_61 AC 3 ms
4,380 KB
testcase_62 AC 2 ms
4,380 KB
testcase_63 AC 17 ms
5,592 KB
testcase_64 AC 4 ms
4,380 KB
testcase_65 AC 10 ms
4,800 KB
testcase_66 AC 8 ms
4,608 KB
testcase_67 AC 4 ms
4,376 KB
testcase_68 AC 9 ms
4,672 KB
testcase_69 AC 12 ms
4,948 KB
testcase_70 AC 6 ms
4,380 KB
testcase_71 AC 4 ms
4,380 KB
testcase_72 AC 11 ms
5,088 KB
testcase_73 AC 5 ms
4,376 KB
testcase_74 AC 12 ms
4,892 KB
testcase_75 AC 8 ms
4,704 KB
testcase_76 AC 3 ms
4,380 KB
testcase_77 AC 8 ms
4,608 KB
testcase_78 AC 14 ms
5,312 KB
testcase_79 AC 15 ms
5,308 KB
testcase_80 AC 13 ms
5,244 KB
testcase_81 AC 14 ms
5,392 KB
testcase_82 AC 13 ms
5,208 KB
testcase_83 AC 238 ms
25,896 KB
testcase_84 AC 251 ms
25,468 KB
testcase_85 AC 124 ms
17,052 KB
testcase_86 AC 188 ms
22,448 KB
testcase_87 AC 216 ms
24,116 KB
testcase_88 AC 22 ms
6,620 KB
testcase_89 AC 239 ms
25,848 KB
testcase_90 AC 135 ms
17,888 KB
testcase_91 AC 97 ms
14,924 KB
testcase_92 AC 44 ms
9,308 KB
testcase_93 AC 176 ms
21,340 KB
testcase_94 AC 153 ms
19,728 KB
testcase_95 AC 155 ms
19,516 KB
testcase_96 AC 219 ms
24,924 KB
testcase_97 AC 84 ms
13,100 KB
testcase_98 AC 242 ms
24,796 KB
testcase_99 AC 119 ms
16,572 KB
testcase_100 AC 252 ms
26,584 KB
testcase_101 AC 40 ms
8,752 KB
testcase_102 AC 19 ms
6,100 KB
testcase_103 AC 45 ms
9,236 KB
testcase_104 AC 68 ms
11,516 KB
testcase_105 AC 179 ms
21,356 KB
testcase_106 AC 94 ms
13,816 KB
testcase_107 AC 256 ms
25,800 KB
testcase_108 AC 261 ms
25,600 KB
testcase_109 AC 192 ms
21,180 KB
testcase_110 AC 163 ms
19,528 KB
testcase_111 AC 176 ms
20,772 KB
testcase_112 AC 62 ms
11,192 KB
testcase_113 AC 154 ms
19,092 KB
testcase_114 AC 86 ms
13,516 KB
testcase_115 AC 25 ms
6,976 KB
testcase_116 AC 105 ms
15,420 KB
testcase_117 AC 61 ms
11,040 KB
testcase_118 AC 217 ms
24,668 KB
testcase_119 AC 115 ms
16,136 KB
testcase_120 AC 252 ms
24,012 KB
testcase_121 AC 57 ms
10,004 KB
testcase_122 AC 106 ms
14,884 KB
testcase_123 AC 1 ms
4,380 KB
testcase_124 AC 216 ms
43,652 KB
testcase_125 AC 221 ms
43,692 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using i64 = long long;
using u64 = unsigned long long;
#define REP(i, n) for (int i = 0, REP_N_ = (n); i < REP_N_; ++i)
#define ALL(x) std::begin(x), std::end(x)

template <class T>
inline int ssize(const T &a) {
  return (int)std::size(a);
}
template <class T>
inline bool chmax(T &a, T b) {
  return a < b and ((a = std::move(b)), true);
}
template <class T>
inline bool chmin(T &a, T b) {
  return a > b and ((a = std::move(b)), true);
}

template <typename T>
using V = std::vector<T>;

template <typename T>
std::istream &operator>>(std::istream &is, std::vector<T> &a) {
  for (auto &x : a) is >> x;
  return is;
}
template <typename Container>
std::ostream &pprint(const Container &a, std::string_view sep = " ",
                     std::string_view ends = "\n", std::ostream *os = nullptr) {
  if (os == nullptr) os = &std::cout;
  auto b = std::begin(a), e = std::end(a);
  for (auto it = std::begin(a); it != e; ++it) {
    if (it != b) *os << sep;
    *os << *it;
  }
  return *os << ends;
}
template <typename T, typename = void>
struct is_iterable : std::false_type {};
template <typename T>
struct is_iterable<T, std::void_t<decltype(std::begin(std::declval<T>())),
                                  decltype(std::end(std::declval<T>()))>>
    : std::true_type {};

template <typename T, typename = std::enable_if_t<
                          is_iterable<T>::value &&
                          !std::is_same<T, std::string_view>::value &&
                          !std::is_same<T, std::string>::value>>
std::ostream &operator<<(std::ostream &os, const T &a) {
  return pprint(a, ", ", "", &(os << "{")) << "}";
}
template <typename T, typename U>
std::ostream &operator<<(std::ostream &os, const std::pair<T, U> &a) {
  return os << "(" << a.first << ", " << a.second << ")";
}

#ifdef ENABLE_DEBUG
template <typename T>
void pdebug(const T &value) {
  std::cerr << value;
}
template <typename T, typename... Ts>
void pdebug(const T &value, const Ts &... args) {
  pdebug(value);
  std::cerr << ", ";
  pdebug(args...);
}
#define DEBUG(...)                                   \
  do {                                               \
    std::cerr << " \033[33m (L" << __LINE__ << ") "; \
    std::cerr << #__VA_ARGS__ << ":\033[0m ";        \
    pdebug(__VA_ARGS__);                             \
    std::cerr << std::endl;                          \
  } while (0)
#else
#define pdebug(...)
#define DEBUG(...)
#endif

using namespace std;

struct Graph {
  int n;
  V<V<int>> adj;
  map<pair<int, int>, int> edge_id;
  explicit Graph(int n) : n(n), adj(n) {}
  void input_undirected(int m) { input(m, false); }
  void input_directed(int m) { input(m, true); }

 private:
  void input(int m, bool is_directed) {
    for (int i = 0; i < m; ++i) {
      int u, v;  // read as 1-indexed.
      cin >> u >> v;
      u--, v--;  // to 0-indexed.
      adj[u].push_back(v);
      if (not is_directed) adj[v].push_back(u);
      edge_id[{u, v}] = edge_id[{v, u}] = i;
    }
  }
};

struct LowLink {
  using G = vector<vector<int>>;
  const int INF = numeric_limits<int>::max();

  int n;
  G adj;
  vector<int> ord, low;
  vector<int> aps;  // articulation points
  vector<pair<int, int>> bridges;

  explicit LowLink(G g) : n(g.size()), adj(move(g)), ord(n, -1), low(n, INF) {
    init();
  }

 private:
  void init() {
    int ord_counter = 0;

    auto dfs = [&](auto self, int v, int par) -> void {
      ord[v] = ord_counter++;
      low[v] = ord[v];
      bool is_articulation_point = false;
      for (auto u : adj[v]) {
        if (ord[u] < 0) {
          self(self, u, v);
          low[v] = min(low[v], low[u]);
          if (par >= 0 and ord[v] <= low[u]) {
            is_articulation_point = true;
          }
          if (ord[v] < low[u]) {
            bridges.emplace_back(min(u, v), max(u, v));
          }
        } else if (u != par) {  // backward edge
          low[v] = min(low[v], ord[u]);
        }
      }
      // Is the root node an articulatin point?
      if (par < 0 and adj[v].size() >= 2) {
        is_articulation_point = true;
      }
      if (is_articulation_point) aps.push_back(v);
    };

    for (int i = 0; i < n; ++i) {
      if (ord[i] == -1) dfs(dfs, i, -1);
    }

    // sort(aps.begin(), aps.end());
    // sort(bridges.begin(), bridges.end());
  }
};

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);

  int N;
  cin >> N;
  Graph g(N);
  g.input_undirected(N);
  LowLink lowlink(move(g.adj));

  set<int> non_bridges;
  REP(i, N) { non_bridges.insert(i); }
  for (auto [u, v] : lowlink.bridges) {
    int e = g.edge_id[{u, v}];
    non_bridges.erase(e);
  }
  cout << ssize(non_bridges) << '\n';
  bool first = true;
  for (auto x : non_bridges) {
    if (not first) cout << ' ';
    cout << x + 1;
    first = false;
  }
  cout << endl;
}
0