結果
問題 | No.2301 Namorientation |
ユーザー | milanis48663220 |
提出日時 | 2023-05-12 21:44:01 |
言語 | C++17 (gcc 12.3.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 832 ms / 3,000 ms |
コード長 | 3,148 bytes |
コンパイル時間 | 1,850 ms |
コンパイル使用メモリ | 148,772 KB |
実行使用メモリ | 94,788 KB |
最終ジャッジ日時 | 2024-05-06 11:31:42 |
合計ジャッジ時間 | 20,017 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 2 ms
5,248 KB |
testcase_01 | AC | 2 ms
5,248 KB |
testcase_02 | AC | 1 ms
5,376 KB |
testcase_03 | AC | 2 ms
5,376 KB |
testcase_04 | AC | 2 ms
5,376 KB |
testcase_05 | AC | 1 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 | 405 ms
50,816 KB |
testcase_13 | AC | 359 ms
46,464 KB |
testcase_14 | AC | 781 ms
82,560 KB |
testcase_15 | AC | 468 ms
56,192 KB |
testcase_16 | AC | 643 ms
71,168 KB |
testcase_17 | AC | 423 ms
52,736 KB |
testcase_18 | AC | 679 ms
72,704 KB |
testcase_19 | AC | 336 ms
43,776 KB |
testcase_20 | AC | 649 ms
71,936 KB |
testcase_21 | AC | 457 ms
55,424 KB |
testcase_22 | AC | 291 ms
94,788 KB |
testcase_23 | AC | 285 ms
93,360 KB |
testcase_24 | AC | 244 ms
78,552 KB |
testcase_25 | AC | 284 ms
64,632 KB |
testcase_26 | AC | 392 ms
83,056 KB |
testcase_27 | AC | 802 ms
82,688 KB |
testcase_28 | AC | 832 ms
82,816 KB |
testcase_29 | AC | 814 ms
82,816 KB |
testcase_30 | AC | 821 ms
82,816 KB |
testcase_31 | AC | 807 ms
82,816 KB |
ソースコード
#include <iostream> #include <algorithm> #include <iomanip> #include <vector> #include <queue> #include <deque> #include <set> #include <map> #include <tuple> #include <cmath> #include <numeric> #include <functional> #include <cassert> #define debug_value(x) cerr << "line" << __LINE__ << ":<" << __func__ << ">:" << #x << "=" << x << endl; #define debug(x) cerr << "line" << __LINE__ << ":<" << __func__ << ">:" << x << endl; template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; } template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; } using namespace std; typedef long long ll; template<typename T> vector<vector<T>> vec2d(int n, int m, T v){ return vector<vector<T>>(n, vector<T>(m, v)); } template<typename T> vector<vector<vector<T>>> vec3d(int n, int m, int k, T v){ return vector<vector<vector<T>>>(n, vector<vector<T>>(m, vector<T>(k, v))); } template<typename T> void print_vector(vector<T> v, char delimiter=' '){ if(v.empty()) { cout << endl; return; } for(int i = 0; i+1 < v.size(); i++) cout << v[i] << delimiter; cout << v.back() << endl; } struct edge{ int to, idx; edge(int to, int idx): to(to), idx(idx) {} }; using P = pair<int, int>; int main(){ ios::sync_with_stdio(false); cin.tie(0); cout << setprecision(10) << fixed; int n; cin >> n; vector<vector<edge>> g(n); vector<set<int>> h(n); vector<int> a(n), b(n); for(int i = 0; i < n; i++){ cin >> a[i] >> b[i]; a[i]--;b[i]--; g[a[i]].push_back(edge(b[i], i)); g[b[i]].push_back(edge(a[i], i)); h[a[i]].insert(b[i]); h[b[i]].insert(a[i]); } map<P, int> mp; for(int i = 0; i < n; i++){ mp[{a[i], b[i]}] = i; mp[{b[i], a[i]}] = i; } vector<string> ans(n); queue<int> que; for(int i = 0; i < n; i++){ if(h[i].size() == 1) { que.push(i); } } auto del_edge = [&](int u, int v){ h[u].erase(v); h[v].erase(u); if(h[u].size() == 1) { que.push(u); } if(h[v].size() == 1) { que.push(v); } }; while(!que.empty()){ auto u = que.front(); que.pop(); int v = *h[u].begin(); int idx = mp[{u, v}]; if(a[idx] == u){ ans[idx] = "->"; }else{ ans[idx] = "<-"; } del_edge(u, v); } int s = -1; for(int i = 0; i < n; i++){ if(!h[i].empty()){ s = i; break; } } vector<bool> seen(n); vector<int> cycle; function<void(int)> dfs = [&](int v){ seen[v] = true; cycle.push_back(v); for(int to: h[v]){ if(!seen[to]) dfs(to); } }; dfs(s); for(int i = 0; i < cycle.size(); i++){ int j = (i+1)%(cycle.size()); int u = cycle[i]; int v = cycle[j]; int idx = mp[{u, v}]; if(a[idx] == u){ ans[idx] = "->"; }else{ ans[idx] = "<-"; } } print_vector(ans, '\n'); }