結果

問題 No.2301 Namorientation
ユーザー KKT89KKT89
提出日時 2023-05-12 21:43:49
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 421 ms / 3,000 ms
コード長 2,019 bytes
コンパイル時間 3,165 ms
コンパイル使用メモリ 227,116 KB
実行使用メモリ 36,652 KB
最終ジャッジ日時 2024-05-06 11:30:27
合計ジャッジ時間 16,530 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 2 ms
5,376 KB
testcase_03 AC 2 ms
5,376 KB
testcase_04 AC 2 ms
5,376 KB
testcase_05 AC 2 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 214 ms
22,956 KB
testcase_13 AC 189 ms
21,140 KB
testcase_14 AC 418 ms
36,016 KB
testcase_15 AC 232 ms
25,144 KB
testcase_16 AC 328 ms
31,524 KB
testcase_17 AC 222 ms
23,936 KB
testcase_18 AC 355 ms
32,128 KB
testcase_19 AC 169 ms
20,224 KB
testcase_20 AC 356 ms
31,872 KB
testcase_21 AC 227 ms
24,872 KB
testcase_22 AC 239 ms
36,200 KB
testcase_23 AC 221 ms
35,476 KB
testcase_24 AC 182 ms
30,336 KB
testcase_25 AC 116 ms
28,892 KB
testcase_26 AC 147 ms
36,652 KB
testcase_27 AC 412 ms
36,364 KB
testcase_28 AC 419 ms
36,352 KB
testcase_29 AC 421 ms
36,224 KB
testcase_30 AC 411 ms
36,224 KB
testcase_31 AC 418 ms
36,224 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;

mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
ll myRand(ll B) {
    return (ull)rng() % B;
}
inline double time() {
    return static_cast<long double>(chrono::duration_cast<chrono::nanoseconds>(chrono::steady_clock::now().time_since_epoch()).count()) * 1e-9;
}

int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int n; cin >> n;
    vector<int> x(n),y(n);
    vector<vector<int>> g(n);
    vector<int> deg(n);
    for (int i = 0; i < n; ++i) {
        cin >> x[i] >> y[i];
        x[i]--; y[i]--;
        g[x[i]].push_back(y[i]);
        g[y[i]].push_back(x[i]);
        deg[x[i]]++;
        deg[y[i]]++;
    }
    vector<int> uo(n, -1);
    queue<int> q;
    for (int i = 0; i < n; ++i) {
        if (deg[i] == 1) {
            q.push(i);
        }
    }
    set<pair<int,int>> st;
    while (q.size()) {
        int s = q.front(); q.pop();
        for (int t:g[s]) {
            if (st.find({s, t}) == st.end()) {
                uo[s] = t;
                st.insert({s,t});
                st.insert({t,s});
                deg[t]--;
                if (deg[t] == 1 and uo[t] == -1) {
                    q.push(t);
                }
            }
        }
    }
    for (int i = 0; i < n; ++i) {
        if (uo[i] == -1) {
            int s = i;
            while (1) {
                for (int t:g[s]) {
                    if (st.find({s, t}) == st.end()) {
                        uo[s] = t;
                        st.insert({s,t});
                        st.insert({t,s});
                        s = t;
                        break;
                    }
                }
                if (uo[s] != -1) break;
            }
        }
    }
    for (int i = 0; i < n; ++i) {
        if (uo[x[i]] == y[i]) {
            cout << "->" << "\n";
        }
        else {
            cout << "<-" << "\n";
        }
    }
}
0