結果

問題 No.1023 Cyclic Tour
ユーザー tarattata1tarattata1
提出日時 2020-03-08 10:38:52
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 203 ms / 2,000 ms
コード長 1,558 bytes
コンパイル時間 537 ms
コンパイル使用メモリ 62,588 KB
実行使用メモリ 26,880 KB
最終ジャッジ日時 2024-04-24 13:08:33
合計ジャッジ時間 9,512 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
5,248 KB
testcase_01 AC 1 ms
5,376 KB
testcase_02 AC 1 ms
5,376 KB
testcase_03 AC 2 ms
5,376 KB
testcase_04 AC 66 ms
19,072 KB
testcase_05 AC 61 ms
19,072 KB
testcase_06 AC 84 ms
20,864 KB
testcase_07 AC 69 ms
19,840 KB
testcase_08 AC 48 ms
15,744 KB
testcase_09 AC 50 ms
15,488 KB
testcase_10 AC 45 ms
15,360 KB
testcase_11 AC 61 ms
16,128 KB
testcase_12 AC 51 ms
14,976 KB
testcase_13 AC 50 ms
14,208 KB
testcase_14 AC 42 ms
14,208 KB
testcase_15 AC 52 ms
14,592 KB
testcase_16 AC 84 ms
21,120 KB
testcase_17 AC 86 ms
21,376 KB
testcase_18 AC 91 ms
21,632 KB
testcase_19 AC 86 ms
20,992 KB
testcase_20 AC 157 ms
25,728 KB
testcase_21 AC 159 ms
26,240 KB
testcase_22 AC 134 ms
24,320 KB
testcase_23 AC 139 ms
24,448 KB
testcase_24 AC 126 ms
23,424 KB
testcase_25 AC 120 ms
25,856 KB
testcase_26 AC 126 ms
26,240 KB
testcase_27 AC 132 ms
25,344 KB
testcase_28 AC 104 ms
22,784 KB
testcase_29 AC 90 ms
21,632 KB
testcase_30 AC 104 ms
23,808 KB
testcase_31 AC 95 ms
23,424 KB
testcase_32 AC 104 ms
24,576 KB
testcase_33 AC 114 ms
24,960 KB
testcase_34 AC 118 ms
24,320 KB
testcase_35 AC 137 ms
26,112 KB
testcase_36 AC 151 ms
25,344 KB
testcase_37 AC 105 ms
24,960 KB
testcase_38 AC 89 ms
22,272 KB
testcase_39 AC 134 ms
23,808 KB
testcase_40 AC 111 ms
23,680 KB
testcase_41 AC 115 ms
23,808 KB
testcase_42 AC 123 ms
26,240 KB
testcase_43 AC 102 ms
21,632 KB
testcase_44 AC 75 ms
19,456 KB
testcase_45 AC 49 ms
21,376 KB
testcase_46 AC 47 ms
21,248 KB
testcase_47 AC 68 ms
25,856 KB
testcase_48 AC 163 ms
26,752 KB
testcase_49 AC 203 ms
26,624 KB
testcase_50 AC 172 ms
26,624 KB
testcase_51 AC 156 ms
26,880 KB
testcase_52 AC 159 ms
26,752 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <stdio.h>
#include <vector>
#include <set>
#pragma warning(disable:4996) 

using namespace std;

vector<set<pair<int,int> > > g;     // target vertex, directed edge
vector<int> visedge;                // visit flag for each 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(it++);     // erase finished 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 (0-indexed) with normal direction
        if(c[i]==1) {
            g[b[i]].insert(make_pair(a[i],i*2+1));   // i*2+1 means edge i (0-indexed) 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