結果

問題 No.1023 Cyclic Tour
ユーザー merom686merom686
提出日時 2020-04-10 23:04:16
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,537 bytes
コンパイル時間 741 ms
コンパイル使用メモリ 78,980 KB
実行使用メモリ 9,800 KB
最終ジャッジ日時 2023-10-14 04:13:41
合計ジャッジ時間 6,228 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,352 KB
testcase_01 AC 1 ms
4,352 KB
testcase_02 AC 2 ms
4,348 KB
testcase_03 AC 2 ms
4,352 KB
testcase_04 AC 28 ms
6,468 KB
testcase_05 AC 28 ms
6,404 KB
testcase_06 AC 31 ms
6,664 KB
testcase_07 AC 28 ms
6,504 KB
testcase_08 AC 29 ms
6,444 KB
testcase_09 AC 28 ms
6,456 KB
testcase_10 AC 26 ms
6,264 KB
testcase_11 AC 36 ms
6,456 KB
testcase_12 AC 33 ms
6,400 KB
testcase_13 AC 31 ms
6,196 KB
testcase_14 AC 28 ms
6,192 KB
testcase_15 AC 32 ms
6,380 KB
testcase_16 AC 49 ms
8,484 KB
testcase_17 AC 51 ms
8,740 KB
testcase_18 AC 51 ms
8,680 KB
testcase_19 AC 50 ms
8,692 KB
testcase_20 AC 64 ms
8,712 KB
testcase_21 AC 66 ms
8,824 KB
testcase_22 AC 61 ms
8,548 KB
testcase_23 AC 63 ms
8,752 KB
testcase_24 AC 63 ms
8,712 KB
testcase_25 AC 53 ms
8,928 KB
testcase_26 AC 57 ms
9,232 KB
testcase_27 WA -
testcase_28 AC 60 ms
8,712 KB
testcase_29 AC 52 ms
8,500 KB
testcase_30 AC 55 ms
9,120 KB
testcase_31 AC 53 ms
8,824 KB
testcase_32 AC 56 ms
9,800 KB
testcase_33 AC 57 ms
9,472 KB
testcase_34 AC 54 ms
8,472 KB
testcase_35 AC 60 ms
8,836 KB
testcase_36 AC 64 ms
8,768 KB
testcase_37 AC 55 ms
9,344 KB
testcase_38 AC 51 ms
8,772 KB
testcase_39 AC 64 ms
8,824 KB
testcase_40 AC 53 ms
8,768 KB
testcase_41 WA -
testcase_42 AC 54 ms
8,644 KB
testcase_43 AC 57 ms
8,496 KB
testcase_44 AC 33 ms
6,764 KB
testcase_45 AC 34 ms
9,620 KB
testcase_46 AC 33 ms
9,692 KB
testcase_47 AC 34 ms
9,624 KB
testcase_48 AC 59 ms
9,040 KB
testcase_49 AC 58 ms
8,904 KB
testcase_50 AC 60 ms
8,748 KB
testcase_51 WA -
testcase_52 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <cmath>
using namespace std;
using ll = long long;

struct Graph {
    struct Vertex { int n, f, g; };
    struct Edge { int i, n, c; };
    Graph(int n, int m) : v(n, { -1, -1, 0 }), e(m), n(n), m(0) {}
    void add_edge(int i, int j, int c) {
        e[m] = { j, v[i].n, c };
        v[i].n = m;
        m++;
    }
    int dfs(int i, int p, int c, int s) {
        if (v[i].f == s && v[i].g) return 1;
        if (v[i].f >= 0) return 0;
        v[i].f = s;
        v[i].g = 1;

        for (int j = v[i].n; j >= 0; j = e[j].n) {
            Edge& o = e[j];
            if (o.i == p) {
                if (c == 1 && o.c == 1) continue;
            }
            if (dfs(o.i, i, o.c, s)) return 1;
        }
        v[i].g = 0;
        return 0;
    }
    void solve() {
        int b = 0;
        for (int i = 0; i < n; i++) {
            if (v[i].f >= 0) continue;
            if (dfs(i, -1, 0, i)) {
                b = 1;
                break;
            }
        }
        cout << (b ? "Yes" : "No") << endl;
    }
    vector<Vertex> v;
    vector<Edge> e;
    int n, m;
};


int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);

    int n, m;
    cin >> n >> m;

    Graph g(n, m * 2);
    for (int i = 0; i < m; i++) {
        int a, b, c;
        cin >> a >> b >> c;
        a--; b--;

        g.add_edge(a, b, c);
        if (c == 1) g.add_edge(b, a, c);
    }

    g.solve();

    return 0;
}
0