結果
問題 | No.1023 Cyclic Tour |
ユーザー | wk |
提出日時 | 2020-04-10 22:30:50 |
言語 | C++14 (gcc 12.3.0 + boost 1.83.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 4,347 bytes |
コンパイル時間 | 1,913 ms |
コンパイル使用メモリ | 176,072 KB |
実行使用メモリ | 54,620 KB |
最終ジャッジ日時 | 2024-09-15 21:00:23 |
合計ジャッジ時間 | 7,913 ms |
ジャッジサーバーID (参考情報) |
judge6 / judge2 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 2 ms
10,624 KB |
testcase_01 | AC | 2 ms
5,376 KB |
testcase_02 | WA | - |
testcase_03 | AC | 2 ms
5,376 KB |
testcase_04 | AC | 122 ms
8,832 KB |
testcase_05 | AC | 101 ms
8,576 KB |
testcase_06 | AC | 111 ms
8,960 KB |
testcase_07 | AC | 105 ms
8,704 KB |
testcase_08 | AC | 94 ms
7,936 KB |
testcase_09 | AC | 93 ms
7,552 KB |
testcase_10 | AC | 92 ms
7,552 KB |
testcase_11 | WA | - |
testcase_12 | WA | - |
testcase_13 | WA | - |
testcase_14 | AC | 87 ms
7,296 KB |
testcase_15 | WA | - |
testcase_16 | TLE | - |
testcase_17 | -- | - |
testcase_18 | -- | - |
testcase_19 | -- | - |
testcase_20 | -- | - |
testcase_21 | -- | - |
testcase_22 | -- | - |
testcase_23 | -- | - |
testcase_24 | -- | - |
testcase_25 | -- | - |
testcase_26 | -- | - |
testcase_27 | -- | - |
testcase_28 | -- | - |
testcase_29 | -- | - |
testcase_30 | -- | - |
testcase_31 | -- | - |
testcase_32 | -- | - |
testcase_33 | -- | - |
testcase_34 | -- | - |
testcase_35 | -- | - |
testcase_36 | -- | - |
testcase_37 | -- | - |
testcase_38 | -- | - |
testcase_39 | -- | - |
testcase_40 | -- | - |
testcase_41 | -- | - |
testcase_42 | -- | - |
testcase_43 | -- | - |
testcase_44 | -- | - |
testcase_45 | -- | - |
testcase_46 | -- | - |
testcase_47 | -- | - |
testcase_48 | -- | - |
testcase_49 | -- | - |
testcase_50 | -- | - |
testcase_51 | -- | - |
testcase_52 | -- | - |
ソースコード
#include <bits/stdc++.h> #define REP(i, n) for(int i = 0; (i) < (n); (i)++) #define INF 5000000000000000 using namespace std; struct Edge{ int to; long weight; Edge(int t, long w) : to(t), weight(w) {} }; long modpow(long a, long n, long mod) { long res = 1; while (n > 0) { if (n & 1) res = res * a % mod; a = a * a % mod; n >>= 1; } return res; } // a^{-1} mod を計算する long modinv(long a, long mod) { return modpow(a, mod - 2, mod); } struct compare1 { bool operator()(const pair<long, long>& value, const long& key) { return (value.first < key); } bool operator()(const long& key, const pair<long, long>& value) { return (key < value.first); } }; struct UnionFind { vector<int> par; vector<int> rank; UnionFind(int n = 1){ init(n); } void init(int n = 1){ par.resize(n); rank.resize(n); REP(i, n) par[i] = i, rank[i] = 0; } int root(int x){ if(par[x] == x) return x; else return par[x] = root(par[x]); } bool issame(int x, int y){ return root(x) == root(y); } bool merge(int x, int y){ x = root(x); y = root(y); if(x == y) return false; if(rank[x] < rank[y]) swap(x, y); if(rank[x] == rank[y]) rank[x]++; par[y] = x; return true; } }; template<class Abel> struct weightedUnionFind{ vector<int> par; vector<int> rank; vector<Abel> diff_weight; weightedUnionFind(int n = 1, Abel SUM_UNITY = 0){ init(n, SUM_UNITY); } void init(int n = 1, Abel SUM_UNITY = 0){ par.resize(n); rank.resize(n); diff_weight.resize(n); REP(i, n) par[i] = i, rank[i] = 0, diff_weight[i] = SUM_UNITY; } int root(int x){ if(par[x] == x) return x; else{ int r = root(par[x]); diff_weight[x] += diff_weight[par[x]]; return par[x] = r; } } Abel weight(int x){ root(x); return diff_weight[x]; } bool issame(int x, int y){ return root(x) == root(y); } bool merge(int x, int y, Abel w){ w += weight(x); w -= weight(y); x = root(x); y = root(y); if(x == y) return false; if(rank[x] < rank[y]) swap(x, y), w = -w; if(rank[x] == rank[y]) rank[x]++; par[y] = x; diff_weight[y] = w; return true; } Abel diff(int x, int y){ return weight(y) - weight(x); } }; using Graph = vector<vector<int>>; using P = pair<int, int>; /* void dijkstra(int s, int V, Graph &G, long* d){ priority_queue<P, vector<P>, greater<P>> pque; fill(d, d + V, INF); d[s] = 0; pque.push(P(0, s)); while(!pque.empty()){ P p = pque.top(); pque.pop(); int now = p.second; if(d[now] < p.first) continue; REP(i, G[now].size()){ Edge e = G[now][i]; if(d[e.to] > d[now] + e.weight){ d[e.to] = d[now] + e.weight; pque.push(P(d[e.to], e.to)); } } } } */ int GCD(int a, int b){ if(b == 0) return a; if(a < b) return GCD(b, a); else return GCD(b, a%b); } bool dfs(int i, int end, Graph &G, vector<bool> seen){ //cout << i << " " << end << endl; if(i == end && seen[i]) return true; seen[i] = true; for(int j=0;j<G[i].size();j++){ //cout << i << " next " << G[i][j] << endl; if(seen[j]) continue; int temp = G[i][j]; G[i].erase(G[i].begin() + j); if(dfs(G[i][j], end, G, seen)) return true; G[i].insert(G[i].begin() + j, temp); //cout << "revive " << G[i][j] << " = " << temp << endl; } return false; } int main() { int N, M; cin >> N >> M; Graph G(N); REP(i, M){ int a, b, c; cin >> a >> b >> c; a--, b--; if(c == 1){ G[a].push_back(b); G[b].push_back(a); }else{ G[a].push_back(b); } } vector<bool> seen(N); REP(i, N){ REP(j, N) seen[j] = false; if(dfs(i, i, G, seen)){ cout << "Yes" << endl; return 0; } } cout << "No" << endl; return 0; }