結果
| 問題 | 
                            No.1023 Cyclic Tour
                             | 
                    
| コンテスト | |
| ユーザー | 
                             tarattata1
                         | 
                    
| 提出日時 | 2020-03-07 20:49:00 | 
| 言語 | C++14  (gcc 13.3.0 + boost 1.87.0)  | 
                    
| 結果 | 
                             
                                AC
                                 
                             
                            
                         | 
                    
| 実行時間 | 256 ms / 2,000 ms | 
| コード長 | 1,924 bytes | 
| コンパイル時間 | 997 ms | 
| コンパイル使用メモリ | 93,652 KB | 
| 実行使用メモリ | 30,208 KB | 
| 最終ジャッジ日時 | 2024-10-15 19:54:31 | 
| 合計ジャッジ時間 | 10,345 ms | 
| 
                            ジャッジサーバーID (参考情報)  | 
                        judge2 / judge5 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 4 | 
| other | AC * 49 | 
ソースコード
#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;
}
            
            
            
        
            
tarattata1