結果

問題 No.2301 Namorientation
ユーザー KudeKude
提出日時 2023-05-12 22:06:09
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 385 ms / 3,000 ms
コード長 2,082 bytes
コンパイル時間 2,801 ms
コンパイル使用メモリ 244,052 KB
実行使用メモリ 52,024 KB
最終ジャッジ日時 2024-05-06 12:04:44
合計ジャッジ時間 15,084 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
5,248 KB
testcase_01 AC 3 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 215 ms
18,504 KB
testcase_13 AC 163 ms
17,148 KB
testcase_14 AC 371 ms
28,644 KB
testcase_15 AC 220 ms
20,200 KB
testcase_16 AC 306 ms
25,108 KB
testcase_17 AC 197 ms
19,156 KB
testcase_18 AC 311 ms
25,476 KB
testcase_19 AC 150 ms
16,304 KB
testcase_20 AC 299 ms
25,164 KB
testcase_21 AC 217 ms
19,992 KB
testcase_22 AC 236 ms
52,024 KB
testcase_23 AC 234 ms
51,180 KB
testcase_24 AC 189 ms
43,384 KB
testcase_25 AC 158 ms
23,264 KB
testcase_26 AC 211 ms
29,200 KB
testcase_27 AC 367 ms
28,800 KB
testcase_28 AC 385 ms
28,796 KB
testcase_29 AC 370 ms
28,796 KB
testcase_30 AC 372 ms
28,800 KB
testcase_31 AC 369 ms
28,796 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
namespace {
#pragma GCC diagnostic ignored "-Wunused-function"
#include<atcoder/all>
#pragma GCC diagnostic warning "-Wunused-function"
using namespace std;
using namespace atcoder;
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define rrep(i,n) for(int i = (int)(n) - 1; i >= 0; i--)
#define all(x) begin(x), end(x)
#define rall(x) rbegin(x), rend(x)
template<class T> bool chmax(T& a, const T& b) { if (a < b) { a = b; return true; } else return false; }
template<class T> bool chmin(T& a, const T& b) { if (b < a) { a = b; return true; } else return false; }
using ll = long long;
using P = pair<int,int>;
using VI = vector<int>;
using VVI = vector<VI>;
using VL = vector<ll>;
using VVL = vector<VL>;

} int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n;
  VVI to(n);
  vector<P> edges;
  rep(i, n) {
    int a, b;
    cin >> a >> b;
    a--, b--;
    to[a].emplace_back(b);
    to[b].emplace_back(a);
    edges.emplace_back(a, b);
  }
  vector<char> visited(n);
  VI st;
  VI cycle;
  auto dfs1 = [&](auto&& self, int u, int p) -> void {
    if (visited[u]) {
      cycle = VI(find(all(st), u), st.end());
      return;
    }
    visited[u] = true;
    st.emplace_back(u);
    for(int v: to[u]) if (v != p) {
      self(self, v, u);
      if (!cycle.empty()) return;
    }
    st.pop_back();
  };
  dfs1(dfs1, 0, -1);
  assert(cycle.size());
  vector<char> in_cycle(n);
  for(int v: cycle) {
    in_cycle[v] = true;
  }
  map<P, int> dir;
  auto add = [&](int u, int v) {
    assert(dir.count({min(u, v), max(u, v)}) == 0);
    if (u > v) dir[{v, u}] = 1;
    else dir[{u, v}] = 0;
  };
  rep(i, cycle.size()) {
    int u = cycle[i], v = cycle[(i + 1) % cycle.size()];
    add(u, v);
  }
  auto dfs2 = [&](auto&& self, int u, int p) -> void {
    for(int v: to[u]) if (v != p && !in_cycle[v]) {
      add(v, u);
      self(self, v, u);
    }
  };
  for(int r : cycle) dfs2(dfs2, r, -1);
  for(auto [u, v] : edges) {
    assert(dir.count({u, v}));
    int d = dir[{u, v}];
    cout << (d == 0 ? "->" : "<-") << '\n';
  }
}
0