結果
問題 | No.2301 Namorientation |
ユーザー | kwm_t |
提出日時 | 2023-05-12 22:12:15 |
言語 | C++17 (gcc 12.3.0 + boost 1.83.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 2,499 bytes |
コンパイル時間 | 5,026 ms |
コンパイル使用メモリ | 279,416 KB |
実行使用メモリ | 68,008 KB |
最終ジャッジ日時 | 2024-05-06 12:14:41 |
合計ジャッジ時間 | 21,714 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 5 ms
8,192 KB |
testcase_01 | AC | 6 ms
8,192 KB |
testcase_02 | WA | - |
testcase_03 | AC | 5 ms
8,192 KB |
testcase_04 | AC | 6 ms
8,192 KB |
testcase_05 | WA | - |
testcase_06 | WA | - |
testcase_07 | AC | 5 ms
8,064 KB |
testcase_08 | AC | 5 ms
8,192 KB |
testcase_09 | AC | 5 ms
8,192 KB |
testcase_10 | AC | 5 ms
8,192 KB |
testcase_11 | AC | 6 ms
8,192 KB |
testcase_12 | WA | - |
testcase_13 | WA | - |
testcase_14 | WA | - |
testcase_15 | WA | - |
testcase_16 | WA | - |
testcase_17 | WA | - |
testcase_18 | WA | - |
testcase_19 | WA | - |
testcase_20 | WA | - |
testcase_21 | WA | - |
testcase_22 | AC | 363 ms
68,008 KB |
testcase_23 | AC | 350 ms
67,284 KB |
testcase_24 | AC | 293 ms
57,456 KB |
testcase_25 | AC | 233 ms
35,356 KB |
testcase_26 | AC | 308 ms
43,604 KB |
testcase_27 | WA | - |
testcase_28 | WA | - |
testcase_29 | WA | - |
testcase_30 | WA | - |
testcase_31 | WA | - |
コンパイルメッセージ
main.cpp: In function 'int main()': main.cpp:80:26: warning: ignoring return value of 'std::queue<_Tp, _Sequence>::reference std::queue<_Tp, _Sequence>::front() [with _Tp = int; _Sequence = std::deque<int, std::allocator<int> >; reference = int&]', declared with attribute 'nodiscard' [-Wunused-result] 80 | que.front(); | ~~~~~~~~~^~ In file included from /home/linuxbrew/.linuxbrew/Cellar/gcc@12/12.3.0/include/c++/12/queue:64, from /home/linuxbrew/.linuxbrew/Cellar/gcc@12/12.3.0/include/c++/12/x86_64-pc-linux-gnu/bits/stdc++.h:86, from main.cpp:1: /home/linuxbrew/.linuxbrew/Cellar/gcc@12/12.3.0/include/c++/12/bits/stl_queue.h:233:7: note: declared here 233 | front() | ^~~~~
ソースコード
#include <bits/stdc++.h> #include <atcoder/all> using namespace std; using namespace atcoder; //using mint = modint1000000007; //const int mod = 1000000007; //using mint = modint998244353; //const int mod = 998244353; //const int INF = 1e9; //const long long LINF = 1e18; #define rep(i, n) for (int i = 0; i < (n); ++i) #define rep2(i,l,r)for(int i=(l);i<(r);++i) #define rrep(i, n) for (int i = (n-1); i >= 0; --i) #define rrep2(i,l,r)for(int i=(r-1);i>=(l);--i) #define all(x) (x).begin(),(x).end() #define allR(x) (x).rbegin(),(x).rend() #define endl "\n" #define P pair<int,int> template<typename A, typename B> inline bool chmax(A & a, const B & b) { if (a < b) { a = b; return true; } return false; } template<typename A, typename B> inline bool chmin(A & a, const B & b) { if (a > b) { a = b; return true; } return false; } vector<int>to[200005]; vector<int>cyid; bool dfs(int v, int c, int p = -1) { bool ret = false; if (v == c)ret = true; for (auto nv : to[v]) { if (p == nv) continue; if (dfs(nv, c, v)) { ret = true; } } if (ret)cyid.push_back(v); return ret; } int main() { ios::sync_with_stdio(false); cin.tie(nullptr); int n; cin >> n; vector<P>ed(n); map<P, P>mp; rep(i, n) { int u, v; cin >> u >> v; u--, v--; ed[i] = { u,v }; mp[{u, v}] = { i,1 }; mp[{v, u}] = { i,-1 }; } vector<int>ans(n, 0); set<int>st; { // サイクルを取得する dsu uf(n); rep(i, n) { if (uf.same(ed[i].first, ed[i].second)) { if (cyid.empty())dfs(ed[i].first, ed[i].second); } else { uf.merge(ed[i].first, ed[i].second); } to[ed[i].first].emplace_back(ed[i].second); to[ed[i].second].emplace_back(ed[i].first); } rep(i, cyid.size()) { st.insert(cyid[i]); //cout << mp[{cyid[i], cyid[(i + 1) % cyid.size()]}].first << " " << mp[{cyid[i], cyid[(i + 1) % cyid.size()]}].second << endl; ans[mp[{cyid[i], cyid[(i + 1) % cyid.size()]}].first] = mp[{cyid[i], cyid[(i + 1) % cyid.size()]}].second; } } queue<int>que; vector<int>cnt(n); rep(i, n) { cnt[i] = to[i].size(); if (1 == to[i].size()) { que.push(i); cnt[i]--; } } while (!que.empty()) { int top = que.front(); que.front(); que.pop(); if (st.count(top))break; rep(i, to[top].size()) { if (0 == cnt[to[top][i]])continue; que.push(to[top][i]); cnt[to[top][i]]--; ans[mp[{to[top][i], top}].first] = mp[{to[top][i], top}].second; } } rep(i, n) { if (1 == ans[i])cout << "<-" << endl; else cout << "->" << endl; } return 0; }