結果

問題 No.1023 Cyclic Tour
ユーザー fuppy_kyoprofuppy_kyopro
提出日時 2020-04-10 23:31:08
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 3,749 bytes
コンパイル時間 1,852 ms
コンパイル使用メモリ 179,196 KB
実行使用メモリ 31,904 KB
最終ジャッジ日時 2023-10-14 07:24:52
合計ジャッジ時間 13,976 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,348 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 112 ms
17,368 KB
testcase_05 AC 113 ms
17,572 KB
testcase_06 AC 128 ms
18,872 KB
testcase_07 AC 117 ms
18,108 KB
testcase_08 WA -
testcase_09 AC 116 ms
15,272 KB
testcase_10 AC 101 ms
15,592 KB
testcase_11 AC 139 ms
16,464 KB
testcase_12 AC 127 ms
15,680 KB
testcase_13 AC 117 ms
14,916 KB
testcase_14 AC 95 ms
14,972 KB
testcase_15 AC 122 ms
15,056 KB
testcase_16 AC 173 ms
18,120 KB
testcase_17 AC 177 ms
18,160 KB
testcase_18 AC 184 ms
17,624 KB
testcase_19 AC 177 ms
17,560 KB
testcase_20 AC 250 ms
20,072 KB
testcase_21 AC 252 ms
20,724 KB
testcase_22 AC 244 ms
19,696 KB
testcase_23 AC 243 ms
19,604 KB
testcase_24 AC 233 ms
19,160 KB
testcase_25 WA -
testcase_26 WA -
testcase_27 AC 219 ms
19,988 KB
testcase_28 AC 209 ms
18,488 KB
testcase_29 AC 181 ms
17,652 KB
testcase_30 AC 202 ms
19,296 KB
testcase_31 AC 189 ms
19,964 KB
testcase_32 AC 206 ms
23,184 KB
testcase_33 WA -
testcase_34 AC 210 ms
18,976 KB
testcase_35 AC 229 ms
20,552 KB
testcase_36 AC 243 ms
19,968 KB
testcase_37 AC 200 ms
22,504 KB
testcase_38 AC 188 ms
19,240 KB
testcase_39 AC 235 ms
19,152 KB
testcase_40 AC 195 ms
19,032 KB
testcase_41 WA -
testcase_42 WA -
testcase_43 AC 191 ms
17,636 KB
testcase_44 WA -
testcase_45 AC 144 ms
30,384 KB
testcase_46 AC 140 ms
30,452 KB
testcase_47 AC 162 ms
31,904 KB
testcase_48 AC 217 ms
20,904 KB
testcase_49 AC 209 ms
20,184 KB
testcase_50 AC 214 ms
21,180 KB
testcase_51 AC 208 ms
20,660 KB
testcase_52 AC 218 ms
21,144 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
 
using namespace std;
 
#define DEBUG(x) cerr<<#x<<": "<<x<<endl;
#define DEBUG_VEC(v) cerr<<#v<<":";for(int i=0;i<v.size();i++) cerr<<" "<<v[i]; cerr<<endl;
#define DEBUG_MAT(v) cerr<<#v<<endl;for(int i=0;i<v.size();i++){for(int j=0;j<v[i].size();j++) {cerr<<v[i][j]<<" ";}cerr<<endl;}
typedef long long ll;
#define int ll
 
#define vi vector<int>
#define vl vector<ll>
#define vii vector< vector<int> >
#define vll vector< vector<ll> >
#define vs vector<string>
#define pii pair<int,int>
#define pis pair<int,string>
#define psi pair<string,int>
#define pll pair<ll,ll>
template<class S, class T> pair<S, T> operator+(const pair<S, T> &s, const pair<S, T> &t) { return pair<S, T>(s.first + t.first, s.second + t.second); }
template<class S, class T> pair<S, T> operator-(const pair<S, T> &s, const pair<S, T> &t) { return pair<S, T>(s.first - t.first, s.second - t.second); }
template<class S, class T> ostream& operator<<(ostream& os, pair<S, T> p) { os << "(" << p.first << ", " << p.second << ")"; return os; }
#define X first
#define Y second
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)
#define rrep(i,n) for(int i=(int)(n)-1;i>=0;i--)
#define rrep1(i,n) for(int i=(int)(n);i>0;i--)
#define REP(i,a,b) for(int i=a;i<b;i++)
#define in(x, a, b) (a <= x && x < b)
#define all(c) c.begin(),c.end()
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a = b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a = b; return 1; } return 0; }
#define UNIQUE(v) v.erase(std::unique(v.begin(), v.end()), v.end());
const ll inf = 1000000001;
const ll INF = (ll)1e18 + 1;
const long double pi = 3.1415926535897932384626433832795028841971L;
#define Sp(p) cout<<setprecision(25)<< fixed<<p<<endl;
//int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
//int dx2[8] = { 1,1,0,-1,-1,-1,0,1 }, dy2[8] = { 0,1,1,1,0,-1,-1,-1 };
vi dx = {1, 0, -1, 0}, dy = {0, 1, 0, -1};
vi dx2 = { 1,1,0,-1,-1,-1,0,1 }, dy2 = { 0,1,1,1,0,-1,-1,-1 };
#define fio() cin.tie(0); ios::sync_with_stdio(false);
const ll MOD = 1000000007;
//const ll MOD = 998244353;
// #define mp make_pair
//#define endl '\n'

vector<vector<vector<pii>>> G(3);
vii visited;

bool dfs(int now, int from, int state, int turn) {
    visited[now][state] = turn;
    vi idx = {0, 1};
    for (int i: idx) {
        int nstate = 0;
        for (pii v: G[i][now]) {
            if (v.second == from) continue;
            if (visited[v.first][nstate] == turn) return true;
            if (visited[v.first][nstate] == 0) {
                if (dfs(v.first, v.second, nstate, turn)) return true;
            }
        }
    }
    visited[now][state] = -1;
    return false;
}

signed main() {
    int n, m;
    cin >> n >> m;
    rep (i, 2) {
        G[i].resize(n);
    }
    visited.resize(n);
    rep (i, n) {
        visited[i].resize(2);
        rep (j, 2) visited[i][j] = 0;
    }

    rep (i, m) {
        int u, v, t;
        cin >> u >> v >> t;
        u--; v--;
        if (t == 1) {
            G[0][u].push_back(pii(v, i));
            G[0][v].push_back(pii(u, i));
        }
        else {
            G[1][u].push_back(pii(v, i));
        }
    }

    // rep (i, 3) {
    //     DEBUG(i);
    //     rep (u, n) {
    //         cout << u << ": ";
    //         for (pii v: G[i][u]) {
    //             cout << v << " ";
    //         }
    //         cout << endl;
    //     }
    // }

    int turn = 1;
    rep (i, n) {
        if (visited[i][0] != 0) continue;
        if (dfs(i, -1, 0, turn)) {
            //DEBUG_MAT(visited);
            cout << "Yes" << endl;
            return 0;
        }
        //DEBUG_MAT(visited);
        turn++;
    }
    cout << "No" << endl;
}
0