結果

問題 No.1023 Cyclic Tour
ユーザー ei13337ei13337
提出日時 2020-04-10 22:57:22
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 2,199 bytes
コンパイル時間 1,637 ms
コンパイル使用メモリ 124,884 KB
実行使用メモリ 21,508 KB
最終ジャッジ日時 2023-10-14 03:54:28
合計ジャッジ時間 9,424 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,368 KB
testcase_01 AC 2 ms
4,348 KB
testcase_02 AC 1 ms
4,348 KB
testcase_03 AC 2 ms
4,352 KB
testcase_04 AC 59 ms
9,508 KB
testcase_05 AC 63 ms
9,696 KB
testcase_06 AC 82 ms
10,952 KB
testcase_07 AC 70 ms
10,120 KB
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 AC 70 ms
11,952 KB
testcase_12 AC 55 ms
13,048 KB
testcase_13 AC 56 ms
12,484 KB
testcase_14 WA -
testcase_15 AC 58 ms
12,484 KB
testcase_16 AC 113 ms
15,952 KB
testcase_17 AC 113 ms
16,284 KB
testcase_18 AC 123 ms
15,656 KB
testcase_19 AC 111 ms
15,388 KB
testcase_20 WA -
testcase_21 WA -
testcase_22 AC 115 ms
11,812 KB
testcase_23 WA -
testcase_24 AC 121 ms
13,908 KB
testcase_25 AC 123 ms
11,224 KB
testcase_26 AC 117 ms
11,000 KB
testcase_27 AC 104 ms
10,372 KB
testcase_28 WA -
testcase_29 WA -
testcase_30 WA -
testcase_31 WA -
testcase_32 WA -
testcase_33 AC 120 ms
13,396 KB
testcase_34 AC 115 ms
11,272 KB
testcase_35 AC 116 ms
11,160 KB
testcase_36 WA -
testcase_37 AC 112 ms
13,848 KB
testcase_38 WA -
testcase_39 AC 113 ms
12,116 KB
testcase_40 AC 115 ms
12,600 KB
testcase_41 WA -
testcase_42 AC 132 ms
11,252 KB
testcase_43 WA -
testcase_44 AC 66 ms
9,364 KB
testcase_45 AC 83 ms
21,464 KB
testcase_46 AC 90 ms
21,508 KB
testcase_47 AC 62 ms
13,580 KB
testcase_48 AC 97 ms
10,648 KB
testcase_49 AC 89 ms
11,008 KB
testcase_50 AC 93 ms
10,712 KB
testcase_51 AC 89 ms
10,592 KB
testcase_52 AC 93 ms
10,708 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <unordered_set>
#include <unordered_map>
#include <stack>
#include <queue>
#include <algorithm>
#include <cassert>
#include <random>
#include <iomanip>
#include <bitset>
#define FOR(i, n, m) for(ll i = n; i < (int)m; i++)
#define REP(i, n) FOR(i, 0, n)
#define ALL(v) v.begin(), v.end()
#define pb push_back
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
constexpr ll inf = 1000000000;
constexpr ll mod = 998244353;
constexpr long double eps = 1e-9;

struct Edge {
    int to;
    int ty;
};

vector<vector<Edge>> g;
vector<vector<int>> ng;

void dfs(int v, vector<int>& gr, int c) {
    gr[v] = c;
    for(auto elm: g[v]) {
        if(gr[elm.to] != -1 || elm.ty == 2) continue;
        dfs(elm.to, gr, c);
    }
    return;
}

bool dfs2(int v, vector<bool>& used) {
    used[v] = true;
    bool ret = false;
    for(auto elm: ng[v]) {
        if(used[elm]) ret = true;
        else ret = ret | dfs2(elm, used);
    }
    return ret;
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n, m;
    cin >> n >> m;
    g.resize(n);
    REP(i, m) {
        int a, b, c;
        cin >> a >> b >> c;
        a--; b--;
        if(c == 1) {
            g[a].pb({b, c});
            g[b].pb({a, c});
        } else {
            g[a].pb({b, c});
        }
    }
    vector<int> gr(n, -1), grc, grec;
    int c = 0;
    REP(i, n) {
        if(gr[i] != -1) continue;
        dfs(i, gr, c);
        c++;
    }
    grc.assign(c, 0); grec.assign(c, 0);
    ng.resize(c);
    REP(i, n) {
        grc[gr[i]]++;
        for(auto elm: g[i]) {
            if(gr[i] != gr[elm.to]) {
                ng[gr[i]].pb(gr[elm.to]);
            } else {
                if(i < elm.to) grec[gr[i]]++;
            }
        }
    }
    REP(i, c) {
        if(grc[i] <= grec[i]) {
            cout << "Yes" << endl;
            return 0;
        }
    }
    REP(i, c) {
        sort(ng[i].begin(), ng[i].end());
        ng[i].erase(unique(ng[i].begin(), ng[i].end()), ng[i].end());
    }
    vector<bool> used(c, false);
    if(dfs2(0, used)) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}
0