結果
問題 | No.1023 Cyclic Tour |
ユーザー |
|
提出日時 | 2024-06-18 00:11:23 |
言語 | C++23 (gcc 13.3.0 + boost 1.87.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 2,535 bytes |
コンパイル時間 | 1,939 ms |
コンパイル使用メモリ | 146,448 KB |
実行使用メモリ | 17,008 KB |
最終ジャッジ日時 | 2024-06-18 00:11:36 |
合計ジャッジ時間 | 13,203 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 39 WA * 10 |
ソースコード
#include <algorithm>#include <cassert>#include <cstdio>#include <cstdlib>#include <cstring>#include <cmath>#include <iostream>#include <numeric>#include <vector>#include <map>#include <set>#include <queue>#include <functional>#include <iomanip>using namespace std;using ll = long long;class range {private: struct I{int x;int operator*(){return x;}bool operator!=(I& lhs){return x<lhs.x;}void operator++(){++x;}};I i,n;public:range(int n_):i({0}),n({n_}){}range(int i_,int n_):i({i_}),n({n_}){}I& begin(){return i;}I& end(){return n;}};template<class T, class U> ostream& operator<<(ostream& os, const pair<T, U>& p){ return os << "{" << p.first << ", " << p.second << "}"; }template<typename T> ostream& operator<<(ostream& os, const vector<T>& obj) { os << "{"; for (const auto& e : obj) os << e << ", "; return os << "}";}template<typename T> ostream& operator<<(ostream& os, const set<T>& obj) { os << "set{"; for (const auto& e : obj) os << e << ", "; return os << "}";}template<typename T, typename U> ostream& operator<<(ostream& os, const map<T, U>& obj) { os << "map{"; for (const auto& e : obj) os << e << ", ";return os << "}"; }#ifdef ONLINE_JUDGE#define dump(expr) ;#else#define dump(expr) { cerr << "\033[33m#L" << __LINE__ << ": " << expr << "\033[39m" << endl; }#endifstruct E {int fr, to, c;E(int fr_, int to_, int c_) : fr(fr_), to(to_), c(c_) {}friend ostream &operator<<(ostream &os, const E &e) { os << "(" << e.fr << " -> " << e.to << ")"; return os; }};typedef vector<E> V;// typedef vector<V> G;// note that each vertex will have both enterning edges & entered edgesvoid add_edge(vector<V> &vg, int fr, int to, int c) {vg[fr].push_back(E(fr, to, c));}ll solve() {int n, m; cin >> n >> m;vector<V> vg(n + 1);for (int i : range(m)) {int a, b, c; cin >> a >> b >> c;add_edge(vg, a, b, c);if (c == 1) {add_edge(vg, b, a, c);}}vector<int> visited(n + 1);function<int(int, int)> dfs;int phase = 1;dfs = [&](int idx, int prev) -> int {dump(idx << " " << prev);if (visited[idx] > 0) {return visited[idx] == phase;}visited[idx] = phase;for (auto e : vg[idx]) if (e.to != prev || e.c == 2) {if (dfs(e.to, e.c == 1 ? idx : -1)) return 1;}return 0;};for (int i : range(1, n + 1)) {phase = i;dump(phase);if (dfs(i, -1)) return 1;}return 0;}int main() {cout << fixed << setprecision(12);cout << (solve() ? "Yes" : "No") << endl;}