結果
| 問題 |
No.2301 Namorientation
|
| コンテスト | |
| ユーザー |
Kude
|
| 提出日時 | 2023-05-12 22:06:09 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 528 ms / 3,000 ms |
| コード長 | 2,082 bytes |
| コンパイル時間 | 2,649 ms |
| コンパイル使用メモリ | 231,416 KB |
| 最終ジャッジ日時 | 2025-02-12 22:52:15 |
|
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | AC * 30 |
ソースコード
#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';
}
}
Kude