結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,384 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 1 ms
4,376 KB
testcase_05 AC 2 ms
4,376 KB
testcase_06 AC 1 ms
4,376 KB
testcase_07 AC 1 ms
4,380 KB
testcase_08 AC 2 ms
4,380 KB
testcase_09 AC 2 ms
4,380 KB
testcase_10 AC 2 ms
4,380 KB
testcase_11 AC 2 ms
4,380 KB
testcase_12 AC 224 ms
12,540 KB
testcase_13 AC 215 ms
11,540 KB
testcase_14 AC 391 ms
18,564 KB
testcase_15 AC 254 ms
13,336 KB
testcase_16 AC 322 ms
16,124 KB
testcase_17 AC 235 ms
12,876 KB
testcase_18 AC 354 ms
17,036 KB
testcase_19 AC 189 ms
10,912 KB
testcase_20 AC 334 ms
16,432 KB
testcase_21 AC 258 ms
13,088 KB
testcase_22 AC 347 ms
16,916 KB
testcase_23 AC 346 ms
16,964 KB
testcase_24 AC 287 ms
14,584 KB
testcase_25 AC 245 ms
15,504 KB
testcase_26 AC 327 ms
19,292 KB
testcase_27 AC 405 ms
18,820 KB
testcase_28 AC 395 ms
18,676 KB
testcase_29 AC 467 ms
18,476 KB
testcase_30 AC 399 ms
18,544 KB
testcase_31 AC 394 ms
18,492 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