結果

問題 No.1023 Cyclic Tour
ユーザー koyoprokoyopro
提出日時 2020-06-08 22:44:37
言語 C++11
(gcc 11.4.0)
結果
TLE  
実行時間 -
コード長 1,893 bytes
コンパイル時間 2,722 ms
コンパイル使用メモリ 150,836 KB
実行使用メモリ 20,052 KB
最終ジャッジ日時 2023-08-27 05:56:49
合計ジャッジ時間 10,864 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 5 ms
9,116 KB
testcase_01 AC 4 ms
9,128 KB
testcase_02 AC 4 ms
9,140 KB
testcase_03 AC 4 ms
9,152 KB
testcase_04 AC 82 ms
18,996 KB
testcase_05 AC 81 ms
18,964 KB
testcase_06 AC 95 ms
20,052 KB
testcase_07 AC 87 ms
19,456 KB
testcase_08 AC 63 ms
15,632 KB
testcase_09 AC 62 ms
15,476 KB
testcase_10 AC 60 ms
15,368 KB
testcase_11 AC 225 ms
15,960 KB
testcase_12 AC 90 ms
14,600 KB
testcase_13 AC 80 ms
14,328 KB
testcase_14 AC 79 ms
14,304 KB
testcase_15 AC 86 ms
14,496 KB
testcase_16 AC 119 ms
18,732 KB
testcase_17 AC 121 ms
18,924 KB
testcase_18 AC 130 ms
19,028 KB
testcase_19 AC 123 ms
18,752 KB
testcase_20 TLE -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
testcase_31 -- -
testcase_32 -- -
testcase_33 -- -
testcase_34 -- -
testcase_35 -- -
testcase_36 -- -
testcase_37 -- -
testcase_38 -- -
testcase_39 -- -
testcase_40 -- -
testcase_41 -- -
testcase_42 -- -
testcase_43 -- -
testcase_44 -- -
testcase_45 -- -
testcase_46 -- -
testcase_47 -- -
testcase_48 -- -
testcase_49 -- -
testcase_50 -- -
testcase_51 -- -
testcase_52 -- -
権限があれば一括ダウンロードができます

ソースコード

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]==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