結果

問題 No.1023 Cyclic Tour
ユーザー SSRSSSRS
提出日時 2020-04-10 22:36:59
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,803 bytes
コンパイル時間 1,933 ms
コンパイル使用メモリ 181,036 KB
実行使用メモリ 25,392 KB
最終ジャッジ日時 2023-10-14 01:27:13
合計ジャッジ時間 14,251 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,348 KB
testcase_01 AC 1 ms
4,348 KB
testcase_02 AC 2 ms
4,348 KB
testcase_03 AC 1 ms
4,348 KB
testcase_04 AC 103 ms
11,148 KB
testcase_05 AC 105 ms
10,960 KB
testcase_06 AC 118 ms
11,428 KB
testcase_07 AC 111 ms
11,144 KB
testcase_08 AC 127 ms
18,368 KB
testcase_09 AC 123 ms
17,816 KB
testcase_10 AC 119 ms
18,112 KB
testcase_11 AC 133 ms
18,820 KB
testcase_12 AC 123 ms
20,672 KB
testcase_13 AC 115 ms
19,340 KB
testcase_14 AC 116 ms
19,548 KB
testcase_15 AC 123 ms
19,880 KB
testcase_16 AC 208 ms
25,136 KB
testcase_17 AC 214 ms
25,392 KB
testcase_18 AC 214 ms
24,892 KB
testcase_19 AC 209 ms
24,320 KB
testcase_20 AC 228 ms
15,452 KB
testcase_21 AC 232 ms
16,484 KB
testcase_22 AC 233 ms
20,188 KB
testcase_23 AC 240 ms
21,080 KB
testcase_24 AC 241 ms
24,388 KB
testcase_25 AC 239 ms
16,712 KB
testcase_26 AC 204 ms
13,356 KB
testcase_27 AC 185 ms
11,484 KB
testcase_28 AC 237 ms
23,500 KB
testcase_29 AC 220 ms
24,464 KB
testcase_30 AC 243 ms
23,940 KB
testcase_31 AC 227 ms
22,300 KB
testcase_32 AC 228 ms
22,976 KB
testcase_33 AC 253 ms
23,332 KB
testcase_34 WA -
testcase_35 WA -
testcase_36 AC 248 ms
18,340 KB
testcase_37 AC 234 ms
21,188 KB
testcase_38 AC 222 ms
23,240 KB
testcase_39 AC 241 ms
20,476 KB
testcase_40 AC 236 ms
21,348 KB
testcase_41 AC 236 ms
21,072 KB
testcase_42 AC 217 ms
13,544 KB
testcase_43 AC 226 ms
23,668 KB
testcase_44 AC 105 ms
11,168 KB
testcase_45 AC 130 ms
22,020 KB
testcase_46 AC 114 ms
21,912 KB
testcase_47 AC 103 ms
11,092 KB
testcase_48 AC 187 ms
15,184 KB
testcase_49 AC 179 ms
13,744 KB
testcase_50 AC 182 ms
15,104 KB
testcase_51 AC 180 ms
15,064 KB
testcase_52 AC 186 ms
15,076 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
int main(){
  int N, M;
  cin >> N >> M;
  vector<vector<int>> E1(N), E2(N);
  for (int i = 0; i < M; i++){
    int a, b, c;
    cin >> a >> b >> c;
    a--;
    b--;
    if (c == 1){
      E1[a].push_back(b);
      E1[b].push_back(a);
    }
    if (c == 2){
      E2[a].push_back(b);
    }
  }
  int gcount = 0;
  vector<int> G(N, -1);
  for (int i = 0; i < N; i++){
    if (G[i] == -1){
      G[i] = gcount;
      queue<int> Q;
      Q.push(i);
      while (!Q.empty()){
        int v = Q.front();
        Q.pop();
        for (int w : E1[v]){
          if (G[w] == -1){
            G[w] = gcount;
            Q.push(w);
          }
        }
      }
      gcount++;
    }
  }
  vector<int> Vcount(gcount, 0);
  for (int i = 0; i < N; i++){
    Vcount[G[i]]++;
  }
  vector<set<int>> E3(gcount);
  vector<int> Ecount(gcount, 0);
  bool self_loop = false;
  for (int i = 0; i < N; i++){
    for (int j : E2[i]){
      E3[G[i]].insert(G[j]);
      if (G[i] == G[j]){
        Ecount[G[i]]++;
      }
    }
  }
  //トポロジカルソートを試みる
  vector<int> indeg(gcount, 0);
  for (int i = 0; i < gcount; i++){
    for (int j : E3[i]){
      indeg[j]++;
    }
  }
  queue<int> Q;
  for (int i = 0; i < gcount; i++){
    if (indeg[i] == 0){
      Q.push(i);
    }
  }
  int count = 0;
  while (!Q.empty()){
    int v = Q.front();
    Q.pop();
    count++;
    for (int w : E3[v]){
      indeg[w]--;
      if (indeg[w] == 0){
        Q.push(w);
      }
    }
  }
  if (count != gcount){
    cout << "Yes" << endl;
  } else {
    bool res = false;
    for (int i = 0; i < gcount; i++){
      if (Ecount[i] >= Vcount[i]){
        res = true;
      }
    }
    if (res){
      cout << "Yes" << endl;
    } else {
      cout << "No" << endl;
    }
  }
}
0