結果

問題 No.1023 Cyclic Tour
ユーザー ei13337ei13337
提出日時 2020-04-10 23:04:45
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 2,435 bytes
コンパイル時間 1,874 ms
コンパイル使用メモリ 126,644 KB
実行使用メモリ 23,088 KB
最終ジャッジ日時 2023-10-14 04:15:42
合計ジャッジ時間 9,176 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,352 KB
testcase_01 AC 1 ms
4,352 KB
testcase_02 AC 2 ms
4,352 KB
testcase_03 AC 2 ms
4,352 KB
testcase_04 AC 62 ms
9,640 KB
testcase_05 AC 62 ms
9,636 KB
testcase_06 AC 69 ms
10,956 KB
testcase_07 AC 71 ms
10,260 KB
testcase_08 AC 62 ms
11,712 KB
testcase_09 AC 67 ms
14,408 KB
testcase_10 AC 68 ms
13,744 KB
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 AC 59 ms
14,748 KB
testcase_15 WA -
testcase_16 AC 116 ms
17,496 KB
testcase_17 AC 120 ms
18,000 KB
testcase_18 AC 120 ms
17,160 KB
testcase_19 AC 116 ms
17,048 KB
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 AC 121 ms
11,288 KB
testcase_26 AC 114 ms
10,952 KB
testcase_27 AC 102 ms
10,436 KB
testcase_28 AC 122 ms
15,232 KB
testcase_29 AC 117 ms
17,688 KB
testcase_30 AC 124 ms
16,144 KB
testcase_31 AC 115 ms
14,684 KB
testcase_32 AC 115 ms
15,664 KB
testcase_33 AC 118 ms
15,968 KB
testcase_34 AC 105 ms
11,224 KB
testcase_35 AC 109 ms
11,136 KB
testcase_36 WA -
testcase_37 AC 115 ms
13,896 KB
testcase_38 AC 108 ms
15,512 KB
testcase_39 WA -
testcase_40 AC 110 ms
13,656 KB
testcase_41 AC 108 ms
13,592 KB
testcase_42 AC 104 ms
11,200 KB
testcase_43 AC 96 ms
13,296 KB
testcase_44 AC 57 ms
9,368 KB
testcase_45 AC 83 ms
23,088 KB
testcase_46 AC 62 ms
19,652 KB
testcase_47 AC 58 ms
13,660 KB
testcase_48 WA -
testcase_49 WA -
testcase_50 AC 85 ms
10,708 KB
testcase_51 AC 82 ms
10,720 KB
testcase_52 AC 86 ms
10,628 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(elm.ty == 2 || 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 + 1, false);
    vector<int> indeg(c, 0);
    REP(i, c) {
        for(auto adj: ng[i]) indeg[adj]++;
    }
    ng.pb({});
    REP(i, c) {
        if(indeg[i] == 0) ng[c].pb(i);
    }
    bool ok = false;
    if((int)ng[c].size() == 0 || dfs2(c, used)) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}
0