結果

問題 No.1254 補強への架け橋
ユーザー keijakkeijak
提出日時 2020-11-16 07:08:57
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 396 ms / 2,000 ms
コード長 4,837 bytes
コンパイル時間 2,689 ms
コンパイル使用メモリ 222,848 KB
実行使用メモリ 43,904 KB
最終ジャッジ日時 2024-07-23 01:26:58
合計ジャッジ時間 21,648 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 2 ms
5,248 KB
testcase_02 AC 2 ms
5,376 KB
testcase_03 AC 2 ms
5,376 KB
testcase_04 AC 2 ms
5,376 KB
testcase_05 AC 2 ms
5,376 KB
testcase_06 AC 2 ms
5,376 KB
testcase_07 AC 2 ms
5,376 KB
testcase_08 AC 2 ms
5,376 KB
testcase_09 AC 2 ms
5,376 KB
testcase_10 AC 2 ms
5,376 KB
testcase_11 AC 2 ms
5,376 KB
testcase_12 AC 2 ms
5,376 KB
testcase_13 AC 2 ms
5,376 KB
testcase_14 AC 2 ms
5,376 KB
testcase_15 AC 2 ms
5,376 KB
testcase_16 AC 2 ms
5,376 KB
testcase_17 AC 2 ms
5,376 KB
testcase_18 AC 2 ms
5,376 KB
testcase_19 AC 2 ms
5,376 KB
testcase_20 AC 2 ms
5,376 KB
testcase_21 AC 2 ms
5,376 KB
testcase_22 AC 2 ms
5,376 KB
testcase_23 AC 2 ms
5,376 KB
testcase_24 AC 3 ms
5,376 KB
testcase_25 AC 2 ms
5,376 KB
testcase_26 AC 2 ms
5,376 KB
testcase_27 AC 2 ms
5,376 KB
testcase_28 AC 2 ms
5,376 KB
testcase_29 AC 2 ms
5,376 KB
testcase_30 AC 2 ms
5,376 KB
testcase_31 AC 2 ms
5,376 KB
testcase_32 AC 2 ms
5,376 KB
testcase_33 AC 2 ms
5,376 KB
testcase_34 AC 2 ms
5,376 KB
testcase_35 AC 2 ms
5,376 KB
testcase_36 AC 2 ms
5,376 KB
testcase_37 AC 2 ms
5,376 KB
testcase_38 AC 2 ms
5,376 KB
testcase_39 AC 2 ms
5,376 KB
testcase_40 AC 2 ms
5,376 KB
testcase_41 AC 2 ms
5,376 KB
testcase_42 AC 2 ms
5,376 KB
testcase_43 AC 3 ms
5,376 KB
testcase_44 AC 2 ms
5,376 KB
testcase_45 AC 2 ms
5,376 KB
testcase_46 AC 3 ms
5,376 KB
testcase_47 AC 2 ms
5,376 KB
testcase_48 AC 3 ms
5,376 KB
testcase_49 AC 2 ms
5,376 KB
testcase_50 AC 3 ms
5,376 KB
testcase_51 AC 3 ms
5,376 KB
testcase_52 AC 3 ms
5,376 KB
testcase_53 AC 3 ms
5,376 KB
testcase_54 AC 3 ms
5,376 KB
testcase_55 AC 3 ms
5,376 KB
testcase_56 AC 2 ms
5,376 KB
testcase_57 AC 3 ms
5,376 KB
testcase_58 AC 2 ms
5,376 KB
testcase_59 AC 2 ms
5,376 KB
testcase_60 AC 3 ms
5,376 KB
testcase_61 AC 3 ms
5,376 KB
testcase_62 AC 2 ms
5,376 KB
testcase_63 AC 20 ms
5,760 KB
testcase_64 AC 5 ms
5,376 KB
testcase_65 AC 12 ms
5,376 KB
testcase_66 AC 10 ms
5,376 KB
testcase_67 AC 4 ms
5,376 KB
testcase_68 AC 10 ms
5,376 KB
testcase_69 AC 14 ms
5,376 KB
testcase_70 AC 7 ms
5,376 KB
testcase_71 AC 5 ms
5,376 KB
testcase_72 AC 14 ms
5,376 KB
testcase_73 AC 6 ms
5,376 KB
testcase_74 AC 13 ms
5,376 KB
testcase_75 AC 10 ms
5,376 KB
testcase_76 AC 3 ms
5,376 KB
testcase_77 AC 9 ms
5,376 KB
testcase_78 AC 16 ms
5,504 KB
testcase_79 AC 18 ms
5,504 KB
testcase_80 AC 15 ms
5,376 KB
testcase_81 AC 18 ms
5,464 KB
testcase_82 AC 16 ms
5,376 KB
testcase_83 AC 352 ms
26,108 KB
testcase_84 AC 321 ms
25,608 KB
testcase_85 AC 170 ms
17,096 KB
testcase_86 AC 276 ms
22,456 KB
testcase_87 AC 312 ms
24,440 KB
testcase_88 AC 28 ms
6,784 KB
testcase_89 AC 349 ms
25,968 KB
testcase_90 AC 197 ms
17,928 KB
testcase_91 AC 143 ms
15,020 KB
testcase_92 AC 62 ms
9,344 KB
testcase_93 AC 267 ms
21,540 KB
testcase_94 AC 234 ms
19,848 KB
testcase_95 AC 242 ms
19,796 KB
testcase_96 AC 338 ms
24,848 KB
testcase_97 AC 122 ms
13,296 KB
testcase_98 AC 338 ms
25,140 KB
testcase_99 AC 174 ms
16,736 KB
testcase_100 AC 355 ms
26,572 KB
testcase_101 AC 52 ms
8,832 KB
testcase_102 AC 24 ms
6,272 KB
testcase_103 AC 60 ms
9,472 KB
testcase_104 AC 90 ms
11,736 KB
testcase_105 AC 259 ms
21,556 KB
testcase_106 AC 125 ms
14,220 KB
testcase_107 AC 334 ms
26,112 KB
testcase_108 AC 348 ms
25,736 KB
testcase_109 AC 257 ms
21,376 KB
testcase_110 AC 231 ms
19,556 KB
testcase_111 AC 239 ms
20,824 KB
testcase_112 AC 82 ms
11,136 KB
testcase_113 AC 200 ms
19,264 KB
testcase_114 AC 120 ms
13,896 KB
testcase_115 AC 32 ms
7,040 KB
testcase_116 AC 145 ms
15,340 KB
testcase_117 AC 79 ms
11,236 KB
testcase_118 AC 314 ms
24,592 KB
testcase_119 AC 165 ms
16,400 KB
testcase_120 AC 396 ms
24,060 KB
testcase_121 AC 65 ms
10,112 KB
testcase_122 AC 137 ms
15,288 KB
testcase_123 AC 2 ms
5,376 KB
testcase_124 AC 306 ms
43,904 KB
testcase_125 AC 291 ms
43,776 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