結果

問題 No.1023 Cyclic Tour
ユーザー tarattata1tarattata1
提出日時 2020-03-07 10:34:30
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,653 bytes
コンパイル時間 746 ms
コンパイル使用メモリ 89,084 KB
実行使用メモリ 14,464 KB
最終ジャッジ日時 2024-04-23 19:04:33
合計ジャッジ時間 5,731 ms
ジャッジサーバーID
(参考情報)
judge3 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 1 ms
5,376 KB
testcase_03 AC 1 ms
5,376 KB
testcase_04 AC 49 ms
9,728 KB
testcase_05 AC 38 ms
9,856 KB
testcase_06 AC 45 ms
10,368 KB
testcase_07 AC 43 ms
10,112 KB
testcase_08 AC 36 ms
8,832 KB
testcase_09 AC 35 ms
8,576 KB
testcase_10 AC 38 ms
8,576 KB
testcase_11 AC 42 ms
8,960 KB
testcase_12 AC 38 ms
8,704 KB
testcase_13 AC 35 ms
8,320 KB
testcase_14 AC 32 ms
8,320 KB
testcase_15 AC 37 ms
8,448 KB
testcase_16 AC 63 ms
9,728 KB
testcase_17 AC 60 ms
9,984 KB
testcase_18 AC 60 ms
9,688 KB
testcase_19 AC 59 ms
9,728 KB
testcase_20 AC 78 ms
11,264 KB
testcase_21 AC 77 ms
11,264 KB
testcase_22 AC 73 ms
10,752 KB
testcase_23 AC 75 ms
10,752 KB
testcase_24 AC 71 ms
10,368 KB
testcase_25 WA -
testcase_26 WA -
testcase_27 AC 69 ms
10,752 KB
testcase_28 AC 70 ms
10,112 KB
testcase_29 AC 61 ms
9,600 KB
testcase_30 AC 66 ms
10,368 KB
testcase_31 AC 65 ms
10,624 KB
testcase_32 AC 72 ms
11,520 KB
testcase_33 WA -
testcase_34 AC 67 ms
10,624 KB
testcase_35 AC 76 ms
11,264 KB
testcase_36 AC 79 ms
11,008 KB
testcase_37 AC 66 ms
11,392 KB
testcase_38 AC 61 ms
10,240 KB
testcase_39 AC 76 ms
10,496 KB
testcase_40 AC 66 ms
10,232 KB
testcase_41 AC 70 ms
10,368 KB
testcase_42 WA -
testcase_43 AC 69 ms
9,600 KB
testcase_44 WA -
testcase_45 AC 42 ms
14,336 KB
testcase_46 AC 41 ms
14,464 KB
testcase_47 AC 45 ms
14,208 KB
testcase_48 AC 69 ms
10,204 KB
testcase_49 AC 71 ms
10,728 KB
testcase_50 AC 71 ms
10,444 KB
testcase_51 AC 75 ms
10,328 KB
testcase_52 AC 70 ms
10,440 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<pair<int,int> > > g;   // to,edge
vector<int> vis,fin;

bool dfs(int paredge, int curr)
{
    assert(vis[curr]==0);
    vis[curr]=1;
    int siz=(int)g[curr].size();
    int i;
    for(i=0; i<siz; i++) {
        int next=g[curr][i].first;
        int edge=g[curr][i].second;
        if(edge==paredge) continue;
        if(vis[next] && !fin[next]) {
            return true;
        }
        if(vis[next]) {
            continue;
        }
        if(dfs(edge,next)) {
            return true;
        }
    }
    fin[curr]=1;
    return false;
}

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


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