結果

問題 No.2301 Namorientation
ユーザー Jeroen Op de BeekJeroen Op de Beek
提出日時 2023-05-12 21:47:17
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 224 ms / 3,000 ms
コード長 1,758 bytes
コンパイル時間 2,226 ms
コンパイル使用メモリ 209,784 KB
実行使用メモリ 29,824 KB
最終ジャッジ日時 2024-05-06 11:35:15
合計ジャッジ時間 12,483 ms
ジャッジサーバーID
(参考情報)
judge5 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 1 ms
5,376 KB
testcase_02 AC 2 ms
5,376 KB
testcase_03 AC 2 ms
5,376 KB
testcase_04 AC 1 ms
5,376 KB
testcase_05 AC 2 ms
5,376 KB
testcase_06 AC 2 ms
5,376 KB
testcase_07 AC 1 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 113 ms
10,496 KB
testcase_13 AC 96 ms
9,856 KB
testcase_14 AC 222 ms
15,232 KB
testcase_15 AC 126 ms
11,264 KB
testcase_16 AC 177 ms
13,696 KB
testcase_17 AC 117 ms
10,752 KB
testcase_18 AC 180 ms
13,696 KB
testcase_19 AC 92 ms
9,344 KB
testcase_20 AC 186 ms
13,824 KB
testcase_21 AC 120 ms
11,136 KB
testcase_22 AC 158 ms
29,824 KB
testcase_23 AC 154 ms
29,440 KB
testcase_24 AC 130 ms
25,088 KB
testcase_25 AC 87 ms
12,924 KB
testcase_26 AC 116 ms
15,736 KB
testcase_27 AC 219 ms
15,232 KB
testcase_28 AC 221 ms
15,232 KB
testcase_29 AC 224 ms
15,232 KB
testcase_30 AC 216 ms
15,232 KB
testcase_31 AC 217 ms
15,360 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