結果

問題 No.1023 Cyclic Tour
ユーザー merom686merom686
提出日時 2020-04-10 22:57:24
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,481 bytes
コンパイル時間 751 ms
コンパイル使用メモリ 78,880 KB
実行使用メモリ 8,748 KB
最終ジャッジ日時 2023-10-14 03:55:00
合計ジャッジ時間 5,663 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,352 KB
testcase_01 AC 2 ms
4,348 KB
testcase_02 AC 2 ms
4,348 KB
testcase_03 AC 2 ms
4,352 KB
testcase_04 AC 27 ms
5,888 KB
testcase_05 AC 26 ms
6,000 KB
testcase_06 AC 29 ms
6,404 KB
testcase_07 AC 27 ms
6,192 KB
testcase_08 AC 27 ms
6,144 KB
testcase_09 AC 27 ms
5,888 KB
testcase_10 AC 25 ms
6,004 KB
testcase_11 WA -
testcase_12 AC 31 ms
6,136 KB
testcase_13 AC 29 ms
5,928 KB
testcase_14 AC 26 ms
5,980 KB
testcase_15 AC 30 ms
5,928 KB
testcase_16 AC 49 ms
8,292 KB
testcase_17 AC 49 ms
8,296 KB
testcase_18 AC 49 ms
8,236 KB
testcase_19 AC 46 ms
8,208 KB
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 AC 50 ms
8,196 KB
testcase_26 AC 51 ms
8,564 KB
testcase_27 AC 49 ms
8,248 KB
testcase_28 AC 49 ms
8,452 KB
testcase_29 AC 48 ms
8,236 KB
testcase_30 AC 51 ms
8,460 KB
testcase_31 AC 49 ms
8,184 KB
testcase_32 AC 50 ms
8,128 KB
testcase_33 AC 51 ms
8,436 KB
testcase_34 AC 49 ms
8,248 KB
testcase_35 AC 51 ms
8,568 KB
testcase_36 WA -
testcase_37 AC 50 ms
8,484 KB
testcase_38 AC 50 ms
8,188 KB
testcase_39 WA -
testcase_40 AC 49 ms
8,308 KB
testcase_41 AC 49 ms
8,176 KB
testcase_42 AC 50 ms
8,592 KB
testcase_43 AC 48 ms
8,040 KB
testcase_44 AC 31 ms
6,268 KB
testcase_45 AC 31 ms
8,264 KB
testcase_46 AC 30 ms
8,376 KB
testcase_47 AC 33 ms
8,248 KB
testcase_48 WA -
testcase_49 AC 56 ms
8,496 KB
testcase_50 WA -
testcase_51 AC 53 ms
8,712 KB
testcase_52 AC 52 ms
8,500 KB
権限があれば一括ダウンロードができます

ソースコード

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; };
    struct Edge { int i, n, c; };
    Graph(int n, int m) : v(n, { -1, -1 }), 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) return 1;
        if (v[i].f >= 0) return 0;
        v[i].f = s;

        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;
        }
        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