結果
問題 | No.2301 Namorientation |
ユーザー |
|
提出日時 | 2023-05-14 18:31:42 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 166 ms / 3,000 ms |
コード長 | 1,878 bytes |
コンパイル時間 | 1,674 ms |
コンパイル使用メモリ | 183,408 KB |
実行使用メモリ | 39,144 KB |
最終ジャッジ日時 | 2024-11-30 06:10:56 |
合計ジャッジ時間 | 10,755 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 |
other | AC * 30 |
コンパイルメッセージ
main.cpp: In function 'void solve()': main.cpp:50:19: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17' [-Wc++17-extensions] 50 | for (auto [to, id] : G[u]) { | ^ main.cpp: In lambda function: main.cpp:60:19: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17' [-Wc++17-extensions] 60 | for (auto [to, id] : G[u]) { | ^
ソースコード
/*** - Meet Brahmbhatt* - Hard work always pays off**/#include"bits/stdc++.h"using namespace std;#ifdef MeetBrahmbhatt#include "debug.h"#else#define dbg(...) 72#endif#define endl "\n"#define int long longconst long long INF = 4e18;const int32_t M = 1e9 + 7;const int32_t MM = 998244353;void solve() {int n;cin >> n;vector<vector<pair<int, int>>> G(n);vector<int> deg(n);vector<array<int, 2>> E(n);for (int i = 0; i < n; i++) {int u, v;cin >> u >> v;--u; --v;deg[u]++;deg[v]++;E[i] = {u, v};G[u].push_back({v, i});G[v].push_back({u, i});}vector<int> vis(n);queue<int> Q;for (int i = 0; i < n; ++i) {if (deg[i] == 1) {vis[i] = 1;Q.push(i);}}vector<string> ans(n);while (!Q.empty()) {int u = Q.front();Q.pop();deg[u] = 0;for (auto [to, id] : G[u]) {if(deg[to] > 1)ans[id] = E[id][0] == u ? "->" : "<-";if (!vis[to] and --deg[to] == 1) {vis[to] = 1;Q.push(to);}}}function<void(int, int)> dfs = [&](int u, int par) {for (auto [to, id] : G[u]) {if (deg[to] > 1 and to != par) {deg[to]--;ans[id] = E[id][0] == u ? "->" : "<-";dfs(to, u);break;}}};for (int i = 0; i < n; i++) {if (!vis[i]) {dfs(i, -1);break;}}for (int i = 0; i < n; i++) {cout << ans[i] << "\n";}}signed main() {ios_base::sync_with_stdio(0);cin.tie(0);cout << fixed << setprecision(9);int tt = 1;// cin >> tt;while (tt--) solve();return 0;}