結果

問題 No.1023 Cyclic Tour
ユーザー niuezniuez
提出日時 2020-04-10 22:34:02
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 2,241 bytes
コンパイル時間 1,934 ms
コンパイル使用メモリ 179,712 KB
実行使用メモリ 61,484 KB
最終ジャッジ日時 2023-10-14 01:23:17
合計ジャッジ時間 22,851 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,352 KB
testcase_01 AC 1 ms
4,352 KB
testcase_02 AC 1 ms
4,352 KB
testcase_03 AC 1 ms
4,352 KB
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 AC 239 ms
37,460 KB
testcase_10 WA -
testcase_11 AC 261 ms
39,368 KB
testcase_12 AC 228 ms
40,016 KB
testcase_13 AC 214 ms
38,208 KB
testcase_14 AC 223 ms
38,604 KB
testcase_15 AC 228 ms
39,144 KB
testcase_16 AC 382 ms
46,840 KB
testcase_17 AC 390 ms
47,520 KB
testcase_18 AC 392 ms
45,572 KB
testcase_19 AC 385 ms
44,944 KB
testcase_20 AC 453 ms
41,968 KB
testcase_21 AC 459 ms
44,216 KB
testcase_22 AC 424 ms
42,672 KB
testcase_23 AC 434 ms
42,420 KB
testcase_24 AC 395 ms
42,572 KB
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
testcase_28 AC 388 ms
42,088 KB
testcase_29 AC 357 ms
42,128 KB
testcase_30 AC 407 ms
42,736 KB
testcase_31 WA -
testcase_32 WA -
testcase_33 WA -
testcase_34 WA -
testcase_35 WA -
testcase_36 AC 442 ms
41,292 KB
testcase_37 WA -
testcase_38 WA -
testcase_39 AC 413 ms
40,880 KB
testcase_40 WA -
testcase_41 WA -
testcase_42 WA -
testcase_43 AC 360 ms
41,140 KB
testcase_44 WA -
testcase_45 AC 264 ms
61,156 KB
testcase_46 AC 278 ms
61,484 KB
testcase_47 AC 301 ms
40,828 KB
testcase_48 AC 333 ms
42,556 KB
testcase_49 AC 342 ms
43,008 KB
testcase_50 AC 326 ms
42,440 KB
testcase_51 WA -
testcase_52 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
using i64 = long long;
#define rep(i,s,e) for(i64 (i) = (s);(i) < (e);(i)++)
#define all(x) x.begin(),x.end()

template<class T>
static inline std::vector<T> ndvec(size_t&& n, T val) noexcept {
  return std::vector<T>(n, std::forward<T>(val));
}

template<class... Tail>
static inline auto ndvec(size_t&& n, Tail&&... tail) noexcept {
  return std::vector<decltype(ndvec(std::forward<Tail>(tail)...))>(n, ndvec(std::forward<Tail>(tail)...));
}

template<class T, class Cond>
struct chain {
  Cond cond; chain(Cond cond) : cond(cond) {}
  bool operator()(T& a, const T& b) const {
    if(cond(a, b)) { a = b; return true; }
    return false;
  }
};
template<class T, class Cond>
chain<T, Cond> make_chain(Cond cond) { return chain<T, Cond>(cond); }

#include <bits/stdc++.h>
using namespace std;
using i64 = long long;

vector<i64> strongly_connected_components(const vector<vector<i64>>& g) {
  i64 n = g.size();
  vector<vector<i64>> rg(n);
  for(int i = 0;i < n;i++) {
    for(auto j: g[i]) {
      rg[j].push_back(i);
    }
  }

  vector<bool> vis(n,false);
  vector<i64> vs;
  vector<i64> res(n,-1);
  function<void(int)> dfs = [&](int v) {
    vis[v] = true;
    for(auto& t : g[v]) {
      if(!vis[t]) dfs(t);
    }
    vs.push_back(v);
  };

  function<void(int,int)> rdfs = [&](int v,int k) {
    vis[v] = true;
    res[v] = k;
    for(auto to : rg[v]) {
      if(!vis[to]) rdfs(to,k);
    }
  };

  for(int i = 0;i < n;i++) {
    if(!vis[i]) dfs(i);
  }

  vis.assign(n,false);
  int k = 0;
  for(int i = n - 1;i >= 0;i--) {
    if(!vis[vs[i]]) rdfs(vs[i] , k++);
  }
  return res;
}

vector<vector<i64>> G;

int main() {
  i64 N, M;
  cin >> N >> M;
  G.resize(N * 3);
  rep(i,0,N) {
    G[i * 3].push_back(i * 3 + 1);
    G[i * 3 + 1].push_back(i * 3 + 2);
  }
  rep(i,0,M) {
    i64 a, b, c;
    cin >> a >> b >> c;
    a--;
    b--;
    if(c == 1) {
      G[a * 3 + 1].push_back(b * 3 + 2);
      G[b * 3 + 1].push_back(a * 3 + 2);
    }
    else {
      G[a * 3 + 2].push_back(b * 3);
    }
  }
  auto res = strongly_connected_components(G);
  i64 ans = *std::max_element(all(res));
  if(ans + 1 == N * 3) {
    cout << "No" << endl;
  }
  else  {
    cout << "Yes" << endl;
  }
}
0