結果

問題 No.1023 Cyclic Tour
ユーザー tarattata1tarattata1
提出日時 2020-03-07 20:49:00
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 202 ms / 2,000 ms
コード長 1,924 bytes
コンパイル時間 983 ms
コンパイル使用メモリ 93,816 KB
実行使用メモリ 30,592 KB
最終ジャッジ日時 2024-04-23 19:05:48
合計ジャッジ時間 8,180 ms
ジャッジサーバーID
(参考情報)
judge3 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
5,248 KB
testcase_01 AC 1 ms
5,248 KB
testcase_02 AC 1 ms
5,376 KB
testcase_03 AC 1 ms
5,376 KB
testcase_04 AC 62 ms
19,072 KB
testcase_05 AC 59 ms
19,200 KB
testcase_06 AC 71 ms
20,992 KB
testcase_07 AC 68 ms
19,840 KB
testcase_08 AC 47 ms
15,872 KB
testcase_09 AC 48 ms
15,488 KB
testcase_10 AC 44 ms
15,360 KB
testcase_11 AC 63 ms
16,256 KB
testcase_12 AC 52 ms
14,976 KB
testcase_13 AC 48 ms
14,080 KB
testcase_14 AC 41 ms
14,208 KB
testcase_15 AC 51 ms
14,464 KB
testcase_16 AC 85 ms
21,120 KB
testcase_17 AC 87 ms
21,376 KB
testcase_18 AC 85 ms
21,504 KB
testcase_19 AC 84 ms
20,864 KB
testcase_20 AC 169 ms
25,728 KB
testcase_21 AC 160 ms
26,112 KB
testcase_22 AC 148 ms
24,448 KB
testcase_23 AC 148 ms
24,576 KB
testcase_24 AC 133 ms
23,424 KB
testcase_25 AC 120 ms
25,728 KB
testcase_26 AC 133 ms
26,624 KB
testcase_27 AC 132 ms
25,728 KB
testcase_28 AC 116 ms
22,784 KB
testcase_29 AC 95 ms
21,760 KB
testcase_30 AC 105 ms
23,808 KB
testcase_31 AC 106 ms
23,680 KB
testcase_32 AC 112 ms
26,240 KB
testcase_33 AC 105 ms
25,600 KB
testcase_34 AC 116 ms
24,320 KB
testcase_35 AC 131 ms
25,984 KB
testcase_36 AC 155 ms
25,344 KB
testcase_37 AC 110 ms
25,984 KB
testcase_38 AC 91 ms
23,040 KB
testcase_39 AC 151 ms
23,808 KB
testcase_40 AC 104 ms
23,808 KB
testcase_41 AC 113 ms
23,936 KB
testcase_42 AC 120 ms
26,240 KB
testcase_43 AC 99 ms
21,632 KB
testcase_44 AC 68 ms
19,712 KB
testcase_45 AC 55 ms
26,112 KB
testcase_46 AC 56 ms
25,856 KB
testcase_47 AC 76 ms
30,592 KB
testcase_48 AC 202 ms
26,752 KB
testcase_49 AC 195 ms
26,752 KB
testcase_50 AC 185 ms
26,624 KB
testcase_51 AC 172 ms
26,624 KB
testcase_52 AC 171 ms
26,624 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<set<pair<int,int> > > g;     // to, directed edge
vector<int> visedge;                // visit flag for directed edge

bool dfs(int paredge, int curr)
{
    auto it=g[curr].begin();
    while(it!=g[curr].end()) {
        int next=it->first;
        int edge=it->second;
        if(edge/2==paredge/2) {
            ++it;
            continue;
        }
        if(visedge[edge]) {
            return true;
        }
        visedge[edge]=1;
        if (dfs(edge, next)) {
            return true;
        }
        it++;
        g[curr].erase(make_pair(next,edge));
    }
    return false;
}

void solve(int n, int m, const vector<int>& a, const vector<int>& b, const vector<int> c)
{
    g.resize(n);
    visedge.resize(m*2);
    int i;
    for(i=0; i<m; i++) {
        g[a[i]].insert(make_pair(b[i],i*2));                // i*2   means edge i with normal direction
        if(c[i]==1) g[b[i]].insert(make_pair(a[i],i*2+1));  // i*2+1 means edge i with reversed direction
    }
    for(i=0; i<n; i++) {
        bool ret=dfs(-100, i);
        if(ret){
            printf("Yes\n"); return;
        }
    }
    printf("No\n");
    return;
}

int main(int argc, char* argv[])
{
    int n,m;
    scanf("%d%d", &n, &m);
    vector<int> a(m),b(m),c(m);
    int i;
    for(i=0; i<m; i++) {
        scanf("%d%d%d", &a[i], &b[i],&c[i]); a[i]--; b[i]--;
    }
	solve(n, m, a, b, c);

	return 0;
}
0