結果

問題 No.1023 Cyclic Tour
ユーザー SSRSSSRS
提出日時 2020-04-10 22:43:06
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,808 bytes
コンパイル時間 1,904 ms
コンパイル使用メモリ 181,416 KB
実行使用メモリ 25,468 KB
最終ジャッジ日時 2023-10-14 03:16:58
合計ジャッジ時間 14,297 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,348 KB
testcase_01 WA -
testcase_02 AC 2 ms
4,352 KB
testcase_03 WA -
testcase_04 AC 108 ms
10,896 KB
testcase_05 AC 108 ms
10,896 KB
testcase_06 AC 124 ms
11,360 KB
testcase_07 AC 112 ms
10,964 KB
testcase_08 AC 126 ms
18,332 KB
testcase_09 AC 125 ms
17,832 KB
testcase_10 AC 121 ms
17,956 KB
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 AC 118 ms
19,436 KB
testcase_15 WA -
testcase_16 AC 210 ms
25,468 KB
testcase_17 AC 212 ms
25,456 KB
testcase_18 AC 215 ms
24,700 KB
testcase_19 AC 205 ms
24,536 KB
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 AC 247 ms
16,844 KB
testcase_26 AC 217 ms
13,324 KB
testcase_27 AC 192 ms
11,432 KB
testcase_28 AC 246 ms
23,552 KB
testcase_29 AC 226 ms
24,480 KB
testcase_30 AC 251 ms
23,972 KB
testcase_31 AC 235 ms
22,564 KB
testcase_32 AC 233 ms
22,956 KB
testcase_33 AC 253 ms
23,372 KB
testcase_34 AC 251 ms
18,336 KB
testcase_35 AC 239 ms
15,916 KB
testcase_36 WA -
testcase_37 AC 240 ms
21,312 KB
testcase_38 AC 224 ms
23,252 KB
testcase_39 WA -
testcase_40 AC 240 ms
21,256 KB
testcase_41 AC 244 ms
21,224 KB
testcase_42 AC 219 ms
13,648 KB
testcase_43 AC 223 ms
23,544 KB
testcase_44 AC 107 ms
11,196 KB
testcase_45 AC 137 ms
21,668 KB
testcase_46 AC 115 ms
21,916 KB
testcase_47 WA -
testcase_48 WA -
testcase_49 WA -
testcase_50 WA -
testcase_51 AC 185 ms
15,112 KB
testcase_52 AC 188 ms
15,252 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);
  for (int i = 0; i < N; i++){
    for (int j : E1[i]){
      Ecount[G[i]]++;
    }
  }
  for (int i = 0; i < N; i++){
    for (int j : E2[i]){
      E3[G[i]].insert(G[j]);
    }
  }
  //トポロジカルソートを試みる
  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