結果

問題 No.2301 Namorientation
ユーザー take000take000
提出日時 2023-10-28 04:42:17
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,953 bytes
コンパイル時間 2,667 ms
コンパイル使用メモリ 221,660 KB
実行使用メモリ 65,176 KB
最終ジャッジ日時 2023-10-28 04:42:40
合計ジャッジ時間 22,164 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,348 KB
testcase_01 AC 2 ms
4,348 KB
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 AC 2 ms
4,348 KB
testcase_09 AC 2 ms
4,348 KB
testcase_10 WA -
testcase_11 AC 2 ms
4,348 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 235 ms
46,248 KB
testcase_23 AC 231 ms
45,568 KB
testcase_24 AC 192 ms
38,620 KB
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
testcase_28 WA -
testcase_29 WA -
testcase_30 WA -
testcase_31 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

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

struct Namori {
    vector<vector<int>> forest;
    vector<int> loop;
    Namori(vector<vector<int>> &G) {
        int N = G.size();
        vector<int> deg(N);
        forest.resize(N);
        rep(i, N) deg[i] = G[i].size();

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

        while (!q.empty()) {
            int u = q.front();
            q.pop();

            for (int v : G[u]) {
                if (seen[v]) continue;
                deg[v]--;

                forest[u].emplace_back(v);
                forest[v].emplace_back(u);

                if (deg[v] == 1) {
                    q.emplace(v);
                    seen[v] = true;
                }
            }
        }

        rep(i, N) {
            if (!seen[i])
                loop.emplace_back(i);
        }
    }
};

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

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

    Namori g(G);
    vector<int> ans(2 * N);
    rep(i, g.loop.size()) {
        int u = g.loop[i], v = g.loop[(i + 1) % g.loop.size()];
        ans[ids[{u, v}]] = 1;

        if (g.forest[u].size() == 0) continue;

        reverse(g.forest[u].begin(), g.forest[u].end());
        g.forest[u].emplace_back(u);
        rep(j, g.forest[u].size() - 1) {
            ans[ids[{g.forest[u][j], g.forest[u][j + 1]}]] = 1;
        }
    }

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

    return 0;
}
0