結果

問題 No.1023 Cyclic Tour
ユーザー catuppercatupper
提出日時 2020-04-10 22:57:15
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 1,913 bytes
コンパイル時間 1,139 ms
コンパイル使用メモリ 76,528 KB
実行使用メモリ 22,812 KB
最終ジャッジ日時 2023-10-14 03:52:54
合計ジャッジ時間 14,996 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 AC 5 ms
11,100 KB
testcase_02 WA -
testcase_03 AC 5 ms
11,092 KB
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 AC 155 ms
17,720 KB
testcase_12 AC 156 ms
18,016 KB
testcase_13 AC 146 ms
17,548 KB
testcase_14 WA -
testcase_15 AC 155 ms
18,184 KB
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 AC 271 ms
20,128 KB
testcase_21 AC 259 ms
20,272 KB
testcase_22 AC 268 ms
20,284 KB
testcase_23 AC 284 ms
20,720 KB
testcase_24 AC 302 ms
21,932 KB
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
testcase_28 WA -
testcase_29 WA -
testcase_30 WA -
testcase_31 WA -
testcase_32 WA -
testcase_33 WA -
testcase_34 WA -
testcase_35 WA -
testcase_36 AC 268 ms
19,008 KB
testcase_37 WA -
testcase_38 WA -
testcase_39 AC 278 ms
18,660 KB
testcase_40 WA -
testcase_41 WA -
testcase_42 WA -
testcase_43 WA -
testcase_44 WA -
testcase_45 AC 128 ms
22,484 KB
testcase_46 WA -
testcase_47 AC 109 ms
15,700 KB
testcase_48 AC 220 ms
18,972 KB
testcase_49 AC 214 ms
18,952 KB
testcase_50 AC 210 ms
19,148 KB
testcase_51 WA -
testcase_52 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cassert>
#include<cmath>
#include<vector>
#include<map>
#include<set>
#include<string>
#include<queue>
#include<stack>
using namespace std;
#define MOD 1000000007
#define MOD2 998244353
#define INF ((1<<30)-1)
#define LINF (1LL<<60)
#define EPS (1e-10)
typedef long long Int;
typedef pair<Int, Int> P;


int n, m;
vector<int> edge[110000];
vector<int> rev[110000];
vector<int> group[110000];
int a, b, c;
bool done[110000];
Int comp[110000];
vector<int> nodes;

void dfs(int x, int last = -1){
    if(done[x])return;
    done[x] = true;
    for(auto to:edge[x]){
        if(to == last)continue;
        dfs(to, x);
    }
    nodes.push_back(x);
}

void dfs2(int x, int g, int last = -1){
    if(done[x])return;
    done[x] = true;
    group[g].push_back(x);
    comp[x] = g;
    for(auto to:rev[x]){
        if(to == last)continue;
        dfs2(to, g, x);        
    }
}

void scc(){
    for(int i = 1;i <= n;i++){
        dfs(i);
    }
    reverse(nodes.begin(), nodes.end());
    for(auto node:nodes){
        if(!done[node])
            dfs2(node, node);
    }
}

void ok(){
    cout << "Yes" << endl;
    exit(0);
}

void ng(){
    cout <<  "No" << endl;
    exit(0);
}

bool check(int g){
    int V = group[g].size();
    if(V == 0)return false;
    int E = 0;
    cout << "Group " << g << endl;
    for(auto v:group[g]){
        cout << v << " ";
        for(auto to:edge[v]){
            if(comp[to] == g)E++;
        }
    }cout << endl;
    if(E == V+1)return false;
    return true;
}

int main(){
    cin >> n >> m;
    for(int i = 0;i < m;i++){
        cin >> a >> b >> c;
        edge[a].push_back(b);
        rev[b].push_back(a);
        if(c==2){
            edge[b].push_back(a);
            rev[a].push_back(b);
        }
    }

    scc();

    for(int i = 1;i <= n;i++){
        if(check(i))ok();
    }
    ng();
    return 0;
} 
0