結果

問題 No.1023 Cyclic Tour
ユーザー outlineoutline
提出日時 2021-03-12 09:50:00
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,942 bytes
コンパイル時間 1,829 ms
コンパイル使用メモリ 141,296 KB
実行使用メモリ 12,032 KB
最終ジャッジ日時 2024-04-21 20:43:01
合計ジャッジ時間 8,605 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 2 ms
5,376 KB
testcase_03 AC 2 ms
5,376 KB
testcase_04 AC 46 ms
9,984 KB
testcase_05 AC 45 ms
9,856 KB
testcase_06 AC 52 ms
10,496 KB
testcase_07 AC 47 ms
10,368 KB
testcase_08 AC 38 ms
8,960 KB
testcase_09 AC 39 ms
8,832 KB
testcase_10 AC 39 ms
9,088 KB
testcase_11 WA -
testcase_12 AC 45 ms
8,576 KB
testcase_13 AC 43 ms
8,192 KB
testcase_14 AC 35 ms
8,320 KB
testcase_15 AC 45 ms
8,192 KB
testcase_16 AC 68 ms
10,368 KB
testcase_17 AC 74 ms
10,496 KB
testcase_18 AC 68 ms
10,240 KB
testcase_19 AC 72 ms
10,112 KB
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 AC 84 ms
11,520 KB
testcase_26 AC 79 ms
11,520 KB
testcase_27 AC 86 ms
11,136 KB
testcase_28 AC 79 ms
10,624 KB
testcase_29 AC 72 ms
10,112 KB
testcase_30 AC 77 ms
11,136 KB
testcase_31 AC 73 ms
11,008 KB
testcase_32 AC 72 ms
10,496 KB
testcase_33 AC 79 ms
11,136 KB
testcase_34 AC 78 ms
11,136 KB
testcase_35 AC 81 ms
11,648 KB
testcase_36 WA -
testcase_37 AC 73 ms
10,880 KB
testcase_38 AC 65 ms
10,368 KB
testcase_39 WA -
testcase_40 AC 76 ms
11,008 KB
testcase_41 AC 72 ms
11,008 KB
testcase_42 AC 82 ms
12,032 KB
testcase_43 AC 72 ms
10,368 KB
testcase_44 AC 46 ms
10,368 KB
testcase_45 AC 40 ms
11,648 KB
testcase_46 AC 38 ms
11,776 KB
testcase_47 AC 52 ms
11,648 KB
testcase_48 WA -
testcase_49 AC 89 ms
11,000 KB
testcase_50 WA -
testcase_51 AC 72 ms
10,976 KB
testcase_52 AC 75 ms
10,960 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <queue>
#include <string>
#include <map>
#include <set>
#include <stack>
#include <tuple>
#include <deque>
#include <array>
#include <numeric>
#include <bitset>
#include <iomanip>
#include <cassert>
#include <chrono>
#include <random>
#include <limits>
#include <iterator>
#include <functional>
#include <sstream>
#include <fstream>
#include <complex>
#include <cstring>
#include <unordered_map>
#include <unordered_set>
using namespace std;

using ll = long long;
constexpr int INF = 1001001001;
constexpr int mod = 1000000007;
// constexpr int mod = 998244353;

template<class T>
inline bool chmax(T& x, T y){
    if(x < y){
        x = y;
        return true;
    }
    return false;
}
template<class T>
inline bool chmin(T& x, T y){
    if(x > y){
        x = y;
        return true;
    }
    return false;
}

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

    int N, M;
    cin >> N >> M;
    using edge = pair<int, int>;
    vector<vector<edge>> g(N);
    for(int i = 0; i < M; ++i){
        int a, b, c;
        cin >> a >> b >> c;
        --a, --b;
        if(c == 1){
            g[a].emplace_back(b, i);
            g[b].emplace_back(a, i);
        }
        else{
            g[a].emplace_back(b, i);
        }
    }

    vector<int> timestamp(N, -1), used(M);
    int t = 0;
    auto dfs = [&](auto&& self, int from, int s) -> void {
        timestamp[from] = t++;
        for(auto [to, edge_id] : g[from]){
            if(used[edge_id])   continue;
            used[edge_id] = true;
            if(timestamp[to] == -1){
                self(self, to, s);
            }
            else if(timestamp[to] >= s){
                cout << "Yes\n";
                exit(0);
            }
        }
    };

    for(int i = 0; i < N; ++i){
        if(timestamp[i] == -1)  dfs(dfs, i, t);
    }
    cout << "No\n";

    return 0;
}
0