結果

問題 No.2301 Namorientation
ユーザー Jeroen Op de BeekJeroen Op de Beek
提出日時 2023-05-12 21:47:17
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 179 ms / 3,000 ms
コード長 1,758 bytes
コンパイル時間 2,052 ms
コンパイル使用メモリ 209,072 KB
実行使用メモリ 29,628 KB
最終ジャッジ日時 2023-08-19 04:23:46
合計ジャッジ時間 11,989 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 1 ms
4,376 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 1 ms
4,380 KB
testcase_06 AC 1 ms
4,380 KB
testcase_07 AC 1 ms
4,380 KB
testcase_08 AC 1 ms
4,376 KB
testcase_09 AC 1 ms
4,384 KB
testcase_10 AC 1 ms
4,380 KB
testcase_11 AC 1 ms
4,380 KB
testcase_12 AC 96 ms
10,160 KB
testcase_13 AC 84 ms
9,724 KB
testcase_14 AC 174 ms
15,052 KB
testcase_15 AC 112 ms
11,132 KB
testcase_16 AC 137 ms
13,208 KB
testcase_17 AC 100 ms
10,432 KB
testcase_18 AC 176 ms
13,456 KB
testcase_19 AC 79 ms
9,172 KB
testcase_20 AC 145 ms
13,600 KB
testcase_21 AC 104 ms
11,188 KB
testcase_22 AC 140 ms
29,628 KB
testcase_23 AC 135 ms
29,040 KB
testcase_24 AC 115 ms
24,880 KB
testcase_25 AC 77 ms
12,708 KB
testcase_26 AC 101 ms
15,544 KB
testcase_27 AC 179 ms
15,068 KB
testcase_28 AC 165 ms
15,104 KB
testcase_29 AC 175 ms
15,048 KB
testcase_30 AC 175 ms
15,132 KB
testcase_31 AC 175 ms
15,108 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include "bits/stdc++.h"
using namespace std;
#define all(x) begin(x),end(x)
template<typename A, typename B> ostream& operator<<(ostream &os, const pair<A, B> &p) { return os << '(' << p.first << ", " << p.second << ')'; }
template<typename T_container, typename T = typename enable_if<!is_same<T_container, string>::value, typename T_container::value_type>::type> ostream& operator<<(ostream &os, const T_container &v) { string sep; for (const T &x : v) os << sep << x, sep = " "; return os; }
#define debug(a) cerr << "(" << #a << ": " << a << ")\n";
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int,int> pi;
const int mxN = 1e5+1, oo = 1e9;
int main() {
    int n; cin >> n;
    vector<vector<pair<int,int>>> adj(n);
    for(int i=0;i<n;++i) {
        int a,b; cin >> a >> b;
        --a,--b;
        adj[a].push_back({b,i});
        adj[b].push_back({a,-i-1});
    }

    // find cycle, then take it as root.
    
    vector<bool> ans(n),vis(n);
    int root=-1;
    auto dfs = [&](auto&& self, int at, int from) -> void {
        vis[at]=1;
        for(auto [to,id] : adj[at]) if(to!=from) {
            if(vis[to]) {
                root=to;
            } else {
                self(self,to,at);

            }
        }
    };
    dfs(dfs,0,-1);
    fill(all(vis),0);
    auto dfs2 = [&](auto&& self, int at, int from) -> void {
        vis[at]=1;
        for(auto [to,id] : adj[at]) if(to!=from) {
            if(vis[to]) {
                if(to==root)if(id>=0) ans[id]=1;
            } else {
                self(self,to,at);
                if(id>=0) ans[id]=1;
            }
        }
    };
    dfs2(dfs2,root,-1);
    for(auto b : ans) {
        if(b) cout << "<-\n";
        else cout << "->\n";
    }
}
0