結果

問題 No.2301 Namorientation
ユーザー take000take000
提出日時 2023-05-12 22:53:43
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 2,514 bytes
コンパイル時間 3,279 ms
コンパイル使用メモリ 217,556 KB
実行使用メモリ 57,200 KB
最終ジャッジ日時 2023-08-19 05:46:10
合計ジャッジ時間 22,845 ms
ジャッジサーバーID
(参考情報)
judge9 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 1 ms
4,384 KB
testcase_02 AC 1 ms
4,384 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 1 ms
4,380 KB
testcase_05 AC 1 ms
4,380 KB
testcase_06 AC 2 ms
4,384 KB
testcase_07 AC 1 ms
4,384 KB
testcase_08 AC 1 ms
4,384 KB
testcase_09 WA -
testcase_10 WA -
testcase_11 AC 1 ms
4,384 KB
testcase_12 AC 401 ms
25,664 KB
testcase_13 WA -
testcase_14 AC 688 ms
41,036 KB
testcase_15 WA -
testcase_16 WA -
testcase_17 AC 420 ms
26,624 KB
testcase_18 AC 607 ms
36,228 KB
testcase_19 AC 328 ms
22,644 KB
testcase_20 AC 610 ms
36,076 KB
testcase_21 AC 463 ms
27,904 KB
testcase_22 AC 266 ms
57,200 KB
testcase_23 AC 265 ms
56,320 KB
testcase_24 AC 221 ms
47,348 KB
testcase_25 WA -
testcase_26 WA -
testcase_27 AC 773 ms
41,144 KB
testcase_28 WA -
testcase_29 WA -
testcase_30 AC 679 ms
41,004 KB
testcase_31 AC 752 ms
41,004 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; ++i)
typedef long long ll;
using namespace std;

int main() {
    cin.tie(0)->sync_with_stdio(0);

    int N;
    cin >> N;
    map<pair<int, int>, int> edges;
    vector<vector<int>> G(N);
    rep(i, N) {
        int u, v;
        cin >> u >> v;
        u--, v--;
        edges[{u, v}] = i;
        edges[{v, u}] = -i;
        G[u].emplace_back(v);
        G[v].emplace_back(u);
    }

    vector<int> deg(N);
    rep(i, N) deg[i] = G[i].size();

    vector<int> loop;
    {
        vector<bool> seen(N);
        queue<int> q;
        rep(i, N) {
            if (deg[i] == 1) {
                q.push(i);
                seen[i] = true;
            }
        }

        while (!q.empty()) {
            int u = q.front();
            q.pop();
            for (int v : G[u]) {
                if (seen[v]) continue;
                deg[v]--;
                if (deg[v] == 1) {
                    q.push(v);
                    seen[v] = true;
                }
            }
        }
        rep(i, N) {
            if (!seen[i]) {
                auto dfs = [&](auto &&self, int u, int p) -> void {
                    loop.emplace_back(u);
                    seen[u] = true;
                    for (int v : G[u]) {
                        if (v == p) continue;
                        if (seen[v]) continue;
                        self(self, v, u);
                    }
                };
                dfs(dfs, i, -1);
                break;
            }
        }
    }

    int n = loop.size();
    vector<int> ans(N);
    rep(i, n) {
        int u = loop[i];
        int v = loop[(i + 1) % n];
        int id = edges[{u, v}];
        if (id >= 0) {
            ans[id] = 1;
        } else {
            ans[-id] = 2;
        }
    }

    vector<bool>
        seen(N);
    rep(i, n) seen[loop[i]] = true;
    rep(i, n) {
        auto dfs = [&](auto &&self, int u, int p = -1) -> void {
            for (int v : G[u]) {
                if (v == p) continue;
                if (seen[v]) continue;
                seen[v] = true;
                int id = edges[{u, v}];
                if (id > 0) {
                    ans[id] = 2;
                } else {
                    ans[-id] = 1;
                }
                self(self, v, u);
            }
        };
        dfs(dfs, loop[i]);
    }

    rep(i, N) {
        if (ans[i] == 1)
            cout << "->\n";
        else
            cout << "<-\n";
    }

    return 0;
}
0