結果

問題 No.2301 Namorientation
ユーザー NAMIDAIRONAMIDAIRO
提出日時 2023-05-12 22:28:03
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 459 ms / 3,000 ms
コード長 1,692 bytes
コンパイル時間 1,366 ms
コンパイル使用メモリ 124,976 KB
実行使用メモリ 19,596 KB
最終ジャッジ日時 2024-05-06 12:31:27
合計ジャッジ時間 15,184 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
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 1 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 1 ms
5,376 KB
testcase_11 AC 2 ms
5,376 KB
testcase_12 AC 257 ms
12,672 KB
testcase_13 AC 217 ms
11,648 KB
testcase_14 AC 454 ms
18,816 KB
testcase_15 AC 275 ms
13,568 KB
testcase_16 AC 365 ms
16,512 KB
testcase_17 AC 258 ms
12,928 KB
testcase_18 AC 393 ms
16,896 KB
testcase_19 AC 221 ms
11,136 KB
testcase_20 AC 365 ms
16,640 KB
testcase_21 AC 269 ms
13,312 KB
testcase_22 AC 360 ms
17,280 KB
testcase_23 AC 360 ms
17,024 KB
testcase_24 AC 305 ms
14,848 KB
testcase_25 AC 260 ms
15,920 KB
testcase_26 AC 338 ms
19,596 KB
testcase_27 AC 459 ms
18,816 KB
testcase_28 AC 436 ms
18,816 KB
testcase_29 AC 447 ms
18,688 KB
testcase_30 AC 447 ms
18,816 KB
testcase_31 AC 435 ms
18,816 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <queue>
#include <set>
#include <random>
#include <iomanip>
#include <string>
#include <cmath>
#include <complex>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)

template<class T>
using vi = vector<T>;

template<class T>
using vii = vector<vi<T>>;

template<class T>
using viii = vector<vii<T>>;

using P = pair<ll, int>;

struct edge {
    int to, idx;
};

int main()
{
    int n;
    cin >> n;
    vi<int> a(n), b(n);    
    vii<edge> to(n);
    vi<int> deg(n);
    rep(i, n) {
        cin >> a[i] >> b[i];
        a[i]--, b[i]--;
        to[a[i]].push_back({ b[i], i });
        to[b[i]].push_back({ a[i], i });
        deg[a[i]]++, deg[b[i]]++;
    }

    queue<int> q;
    rep(i, n) {
        if (deg[i] == 1) q.push(i);
    }

    vi<int> ans(n);
    while (!q.empty()) {
        int v = q.front();
        q.pop();

        for (edge nv : to[v]) {
            if (ans[nv.idx]) continue;
            if (v > nv.to) ans[nv.idx] = 1;
            else ans[nv.idx] = -1;
            deg[nv.to]--;
            if (deg[nv.to] == 1) q.push(nv.to);
            break;
        }
    }

    
    rep(i, n) {
        q.push(i);
        while (!q.empty()) {
            int v = q.front();
            q.pop();
            for (edge nv : to[v]) {
                if (ans[nv.idx] != 0) continue;
                if (v > nv.to) ans[nv.idx] = 1;
                else ans[nv.idx] = -1;
                q.push(nv.to);
                break;
            }
        }
    }

    rep(i, n) cout << (ans[i] == 1 ? "<-" : "->") << endl;

    return 0;
}

/*
5
4 5
1 5
2 3
1 2
1 5

*/
0