結果

問題 No.1023 Cyclic Tour
ユーザー tarattata1tarattata1
提出日時 2020-03-07 11:27:15
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 2,308 bytes
コンパイル時間 995 ms
コンパイル使用メモリ 89,616 KB
実行使用メモリ 12,344 KB
最終ジャッジ日時 2024-04-23 19:05:09
合計ジャッジ時間 6,908 ms
ジャッジサーバーID
(参考情報)
judge1 / 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 51 ms
9,856 KB
testcase_05 AC 48 ms
9,748 KB
testcase_06 AC 58 ms
10,368 KB
testcase_07 AC 52 ms
10,112 KB
testcase_08 AC 43 ms
8,960 KB
testcase_09 AC 44 ms
8,704 KB
testcase_10 AC 44 ms
8,704 KB
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 AC 41 ms
8,320 KB
testcase_15 WA -
testcase_16 AC 72 ms
9,728 KB
testcase_17 AC 72 ms
9,856 KB
testcase_18 AC 79 ms
9,728 KB
testcase_19 AC 74 ms
9,472 KB
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 AC 90 ms
11,008 KB
testcase_26 AC 83 ms
10,828 KB
testcase_27 AC 79 ms
10,624 KB
testcase_28 AC 84 ms
10,112 KB
testcase_29 AC 76 ms
9,728 KB
testcase_30 AC 81 ms
10,496 KB
testcase_31 AC 81 ms
10,368 KB
testcase_32 AC 80 ms
9,984 KB
testcase_33 AC 88 ms
10,404 KB
testcase_34 AC 85 ms
10,496 KB
testcase_35 AC 91 ms
11,264 KB
testcase_36 WA -
testcase_37 AC 81 ms
10,240 KB
testcase_38 AC 75 ms
9,472 KB
testcase_39 WA -
testcase_40 AC 85 ms
10,240 KB
testcase_41 AC 89 ms
10,240 KB
testcase_42 AC 92 ms
11,136 KB
testcase_43 AC 77 ms
9,728 KB
testcase_44 AC 56 ms
9,984 KB
testcase_45 AC 48 ms
9,472 KB
testcase_46 WA -
testcase_47 WA -
testcase_48 AC 99 ms
11,860 KB
testcase_49 AC 99 ms
12,344 KB
testcase_50 AC 94 ms
11,720 KB
testcase_51 WA -
testcase_52 WA -
権限があれば一括ダウンロードができます

ソースコード

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 curr)
{
    assert(vis[curr]==0);
    vector<pair<int,int> > z;
    {
        int siz=(int)g[curr].size();
        if(siz==0) {
            vis[curr]=fin[curr]=1;
        }
        int i;
        for(i=0; i<siz; i++) {
            int next=g[curr][i].first;
            int edge=g[curr][i].second;
            z.push_back(make_pair(curr,i));
        }
    }
    while(!z.empty()) {
        int curr=z.back().first;
        int id=z.back().second;
        z.pop_back();
        int next=g[curr][id].first;
        int edge=g[curr][id].second;
        if(vis[next] && !fin[next]) {
            return true;
        }
        if(vis[next]) {
            continue;
        }

        {
            int siz=(int)g[next].size();
            if(siz==0) {
                vis[curr]=fin[curr]=1;
            }
            int i;
            for(i=0; i<siz; i++) {
                int next2=g[next][i].first;
                int edge2=g[next][i].second;
                if(edge2==edge) continue;
                z.push_back(make_pair(next,i));
            }
        }
        vis[curr]=1;
        if(id==0) 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(i);
        if(ret){
            printf("Yes\n");
            return;
        }
    }
    printf("No\n");
    return;
}


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