結果

問題 No.1023 Cyclic Tour
ユーザー koyoprokoyopro
提出日時 2020-06-08 22:46:58
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 1,931 bytes
コンパイル時間 3,251 ms
コンパイル使用メモリ 151,104 KB
実行使用メモリ 24,144 KB
最終ジャッジ日時 2023-08-27 06:02:05
合計ジャッジ時間 14,357 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 4 ms
9,212 KB
testcase_01 AC 4 ms
9,184 KB
testcase_02 AC 4 ms
9,092 KB
testcase_03 AC 5 ms
9,148 KB
testcase_04 AC 84 ms
18,944 KB
testcase_05 AC 83 ms
18,928 KB
testcase_06 AC 97 ms
20,048 KB
testcase_07 AC 88 ms
19,388 KB
testcase_08 AC 63 ms
15,656 KB
testcase_09 AC 70 ms
15,460 KB
testcase_10 AC 60 ms
15,312 KB
testcase_11 AC 81 ms
16,048 KB
testcase_12 AC 67 ms
14,696 KB
testcase_13 AC 62 ms
14,284 KB
testcase_14 AC 63 ms
14,336 KB
testcase_15 AC 64 ms
14,576 KB
testcase_16 AC 120 ms
18,760 KB
testcase_17 AC 124 ms
18,936 KB
testcase_18 AC 127 ms
19,052 KB
testcase_19 AC 126 ms
18,472 KB
testcase_20 AC 200 ms
23,384 KB
testcase_21 AC 199 ms
23,584 KB
testcase_22 AC 184 ms
21,940 KB
testcase_23 AC 185 ms
22,060 KB
testcase_24 AC 171 ms
20,716 KB
testcase_25 AC 163 ms
23,384 KB
testcase_26 AC 184 ms
23,900 KB
testcase_27 AC 192 ms
23,232 KB
testcase_28 AC 152 ms
20,580 KB
testcase_29 AC 133 ms
19,320 KB
testcase_30 AC 147 ms
21,016 KB
testcase_31 AC 138 ms
20,968 KB
testcase_32 AC 150 ms
21,784 KB
testcase_33 WA -
testcase_34 AC 164 ms
22,156 KB
testcase_35 AC 186 ms
23,612 KB
testcase_36 AC 195 ms
22,936 KB
testcase_37 AC 155 ms
22,252 KB
testcase_38 AC 135 ms
19,972 KB
testcase_39 AC 178 ms
21,548 KB
testcase_40 AC 149 ms
21,304 KB
testcase_41 AC 153 ms
21,356 KB
testcase_42 AC 171 ms
23,680 KB
testcase_43 AC 153 ms
19,436 KB
testcase_44 WA -
testcase_45 AC 65 ms
19,544 KB
testcase_46 AC 63 ms
19,328 KB
testcase_47 AC 89 ms
24,144 KB
testcase_48 AC 221 ms
23,924 KB
testcase_49 AC 268 ms
23,948 KB
testcase_50 AC 219 ms
23,952 KB
testcase_51 AC 216 ms
23,944 KB
testcase_52 AC 224 ms
23,992 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include "bits/stdc++.h"
using namespace std;
#define int long long
#define FOR(i, a, b) for(int i=(a);i<(b);i++)
#define RFOR(i, a, b) for(int i=(b-1);i>=(a);i--)
#define REP(i, n) for(int i=0; i<(n); i++)
#define RREP(i, n) for(int i=(n-1); i>=0; i--)
#define REP1(i, n) for(int i=1; i<=(n); i++)
#define RREP1(i, n) for(int i=(n); i>=1; i--)
#define ALL(a) (a).begin(),(a).end()
#define UNIQUE_SORT(l) sort(ALL(l)); l.erase(unique(ALL(l)), l.end());
#define CONTAIN(a, b) find(ALL(a), (b)) != (a).end()
#define out(...) printf(__VA_ARGS__)
#define chmax(a,b) a = max(a,b)
#define chmin(a,b) a = min(a,b)
#if DEBUG
#define debug(...) printf(__VA_ARGS__)
#else
#define debug(...) /* ... */
#endif

void solve();
signed main()
{
#if DEBUG
    std::ifstream in("input.txt");
    std::cin.rdbuf(in.rdbuf());
#endif
    cin.tie(0);
    ios::sync_with_stdio(false);
    solve();
    return 0;
}

/*================================*/
#if DEBUG
#define SIZE 100
#else
#define SIZE 123450
#endif

int N,M,Q;
set<int> E[SIZE];
int ST[SIZE];
int NEW=0;
int ACTIVE=1;
int FINISHED=2;

// 閉路が無いかどうか
bool acyclic(int i, int p=-1) {
    if (ST[i]==FINISHED) return true;
    if (ST[i]==ACTIVE) return false;
    ST[i]=ACTIVE;
    for (int j:E[i])if(j!=p) {
        if (!acyclic(j,i)) return false;
    }
    ST[i]=FINISHED;
    return true;
}

void solve() {
    cin>>N>>M;
    bool is_acyclic=true;
    int a,b,c;
    REP(i,M) {
        cin>>a>>b>>c;
        --a;--b;
        if (c==1) {
            if (E[b].count(a) || E[a].count(b)) is_acyclic=false;
        } else {
            if (E[b].count(a)) is_acyclic=false;
        }
        E[a].insert(b);
        if (c==1) E[b].insert(a);
    }
    REP(i,N) {
        if (ST[i]==NEW) {
            if (!acyclic(i)) {
                is_acyclic=false;
                break;
            }
        }
    }
    string ans = is_acyclic ? "No" : "Yes";
    cout << ans << endl;
}

0