結果

問題 No.1023 Cyclic Tour
ユーザー tarattata1tarattata1
提出日時 2020-03-08 09:23:18
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 1,784 bytes
コンパイル時間 821 ms
コンパイル使用メモリ 89,944 KB
実行使用メモリ 19,456 KB
最終ジャッジ日時 2024-04-24 11:15:10
合計ジャッジ時間 13,867 ms
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
10,624 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 1 ms
5,376 KB
testcase_03 AC 2 ms
5,376 KB
testcase_04 AC 39 ms
11,136 KB
testcase_05 AC 39 ms
11,520 KB
testcase_06 AC 46 ms
12,160 KB
testcase_07 AC 41 ms
11,520 KB
testcase_08 AC 39 ms
10,368 KB
testcase_09 AC 43 ms
10,112 KB
testcase_10 AC 48 ms
10,112 KB
testcase_11 AC 1,661 ms
10,624 KB
testcase_12 AC 1,671 ms
10,496 KB
testcase_13 AC 1,536 ms
9,600 KB
testcase_14 AC 81 ms
9,600 KB
testcase_15 AC 1,418 ms
9,856 KB
testcase_16 AC 58 ms
12,800 KB
testcase_17 AC 60 ms
12,928 KB
testcase_18 AC 63 ms
12,928 KB
testcase_19 AC 61 ms
12,544 KB
testcase_20 TLE -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
testcase_31 -- -
testcase_32 -- -
testcase_33 -- -
testcase_34 -- -
testcase_35 -- -
testcase_36 -- -
testcase_37 -- -
testcase_38 -- -
testcase_39 -- -
testcase_40 -- -
testcase_41 -- -
testcase_42 -- -
testcase_43 -- -
testcase_44 -- -
testcase_45 -- -
testcase_46 -- -
testcase_47 -- -
testcase_48 -- -
testcase_49 -- -
testcase_50 -- -
testcase_51 -- -
testcase_52 -- -
権限があれば一括ダウンロードができます

ソースコード

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, directed edge
vector<int> vis,fin;

bool dfs(int paredge, int curr)
{
    assert(vis[curr]==0);
    vis[curr]=1;
    int i;
    for(i=0; i<(int)g[curr].size(); i++) {
        int next=g[curr][i].first;
        int edge=g[curr][i].second;
        if(paredge==edge) 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, int m, const vector<int>& a, const vector<int>& b, const vector<int> c)
{
    g.clear(); g.resize(n);
    int i;
    for(i=0; i<m; i++) {
        g[a[i]].push_back(make_pair(b[i],i));
        if(c[i]==1) g[b[i]].push_back(make_pair(a[i],i));
    }
    for(i=0; i<n; i++) {
        vis.clear(); vis.resize(n);
        fin.clear(); fin.resize(n);
        bool ret=dfs(-1,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