結果

問題 No.1023 Cyclic Tour
ユーザー tarattata1tarattata1
提出日時 2020-03-07 08:16:37
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,592 bytes
コンパイル時間 802 ms
コンパイル使用メモリ 86,584 KB
実行使用メモリ 15,488 KB
最終ジャッジ日時 2024-04-23 19:04:01
合計ジャッジ時間 5,705 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
5,248 KB
testcase_01 AC 1 ms
5,376 KB
testcase_02 AC 2 ms
5,376 KB
testcase_03 AC 2 ms
5,376 KB
testcase_04 AC 39 ms
8,832 KB
testcase_05 AC 39 ms
8,960 KB
testcase_06 AC 43 ms
9,344 KB
testcase_07 AC 40 ms
8,960 KB
testcase_08 AC 33 ms
8,320 KB
testcase_09 AC 34 ms
8,064 KB
testcase_10 AC 33 ms
8,192 KB
testcase_11 WA -
testcase_12 AC 36 ms
8,064 KB
testcase_13 AC 33 ms
7,936 KB
testcase_14 WA -
testcase_15 AC 34 ms
7,936 KB
testcase_16 AC 57 ms
8,832 KB
testcase_17 AC 59 ms
8,832 KB
testcase_18 AC 61 ms
8,576 KB
testcase_19 AC 57 ms
8,448 KB
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 AC 66 ms
9,344 KB
testcase_26 AC 67 ms
9,344 KB
testcase_27 AC 62 ms
9,344 KB
testcase_28 AC 62 ms
8,832 KB
testcase_29 AC 60 ms
8,704 KB
testcase_30 AC 64 ms
9,216 KB
testcase_31 AC 62 ms
9,472 KB
testcase_32 AC 61 ms
8,960 KB
testcase_33 AC 65 ms
9,216 KB
testcase_34 AC 63 ms
9,088 KB
testcase_35 AC 70 ms
9,216 KB
testcase_36 WA -
testcase_37 AC 60 ms
9,344 KB
testcase_38 AC 59 ms
9,472 KB
testcase_39 WA -
testcase_40 AC 63 ms
8,960 KB
testcase_41 AC 65 ms
8,960 KB
testcase_42 AC 69 ms
9,216 KB
testcase_43 AC 59 ms
8,448 KB
testcase_44 AC 42 ms
9,472 KB
testcase_45 AC 40 ms
15,488 KB
testcase_46 AC 39 ms
15,360 KB
testcase_47 AC 48 ms
15,488 KB
testcase_48 WA -
testcase_49 AC 65 ms
9,828 KB
testcase_50 WA -
testcase_51 AC 66 ms
9,672 KB
testcase_52 AC 64 ms
9,536 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <stdio.h>
#include <string>
#include <cstring>
#include <stdlib.h>
#include <math.h>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <list>
#include <iterator>
#include <assert.h>
#pragma warning(disable:4996) 

typedef long long ll;
#define MIN(a, b) ((a)>(b)? (b): (a))
#define MAX(a, b) ((a)<(b)? (b): (a))
#define LINF 9223300000000000000
#define INF 2140000000
const long long MOD = 1000000007;
//const long long MOD = 998244353;

using namespace std;

vector<vector<int> > g;   // to
vector<int> vis;

bool dfs(int par, int curr, int root)
{
    assert(vis[curr]<0);
    vis[curr]=root;
    int siz=(int)g[curr].size();
    int i;
    for(i=0; i<siz; i++) {
        int next=g[curr][i];
        if(next==par) continue;
        if(vis[next]==root) {
            return true;
        }
        if(vis[next]>=0) {
            continue;
        }
        if(dfs(curr,next,root)) {
            return true;
        }
    }
    return false;
}

void solve()
{
    int n,m;
    scanf("%d%d", &n, &m);
    g.resize(n);
    vis.resize(n);
    int i;
    for(i=0; i<n; i++) {
        vis[i]=-1;
    }
    for(i=0; i<m; i++) {
        int a,b,c;
        scanf("%d%d%d", &a, &b,&c); a--; b--;
        g[a].push_back(b);
        if(c==1) g[b].push_back(a);
    }
    for(i=0; i<n; i++) {
        if(vis[i]>=0) continue;
        bool ret=dfs(-1,i,i);
        if(ret){
            printf("Yes\n");
            return;
        }
    }
    printf("No\n");
    return;
}


int main(int argc, char* argv[])
{
	solve();
	return 0;
}
0