結果
問題 |
No.2301 Namorientation
|
ユーザー |
![]() |
提出日時 | 2023-05-12 21:58:03 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,866 bytes |
コンパイル時間 | 1,505 ms |
コンパイル使用メモリ | 124,640 KB |
最終ジャッジ日時 | 2025-02-12 22:42:48 |
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 |
other | AC * 10 WA * 20 |
ソースコード
#include <iostream> #include <vector> #include <algorithm> #include <map> #include <queue> #include <set> #include <random> #include <iomanip> #include <string> #include <cmath> #include <complex> using namespace std; typedef long long ll; #define rep(i, n) for(int i = 0; i < (n); i++) template<class T> using vi = vector<T>; template<class T> using vii = vector<vi<T>>; template<class T> using viii = vector<vii<T>>; using P = pair<ll, int>; void chmin(ll & x, ll y) { x = min(x, y); } void chmax(ll& x, ll y) { x = max(x, y); } struct edge { int to, idx; }; int main() { int n; cin >> n; vi<int> a(n), b(n); vii<edge> to(n); vi<int> deg(n); rep(i, n) { cin >> a[i] >> b[i]; a[i]--, b[i]--; to[a[i]].push_back({ b[i], i }); to[b[i]].push_back({ a[i], i + n }); deg[a[i]]++, deg[b[i]]++; } queue<int> q; rep(i, n) { if (deg[i] == 1) q.push(i); } vi<int> ans(n); vi<bool> visited(n); while (!q.empty()) { int v = q.front(); q.pop(); visited[v] = true; edge nv = to[v].front(); if (nv.idx >= n) ans[nv.idx - n] = 1; else ans[nv.idx] = -1; deg[nv.to]--; if (deg[nv.to] == 1) q.push(nv.to); } rep(i, n) { if (visited[i]) continue; q.push(i); while (!q.empty()) { int v = q.front(); q.pop(); visited[v] = true; for (edge nv : to[v]) { int num = nv.idx; if (num >= n) num -= n; if (ans[num]) continue; if (nv.idx >= n) ans[nv.idx - n] = 1; else ans[nv.idx] = -1; q.push(nv.to); break; } } } rep(i, n) cout << (ans[i] == 1 ? "<-" : "->") << endl; return 0; }