結果
問題 | No.1983 [Cherry 4th Tune C] 南の島のマーメイド |
ユーザー | tnakao0123 |
提出日時 | 2022-06-20 18:28:12 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 201 ms / 4,000 ms |
コード長 | 3,654 bytes |
コンパイル時間 | 928 ms |
コンパイル使用メモリ | 69,184 KB |
実行使用メモリ | 63,080 KB |
最終ジャッジ日時 | 2024-10-13 06:26:51 |
合計ジャッジ時間 | 10,004 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 5 ms
7,808 KB |
testcase_01 | AC | 4 ms
7,680 KB |
testcase_02 | AC | 4 ms
7,808 KB |
testcase_03 | AC | 4 ms
7,680 KB |
testcase_04 | AC | 4 ms
7,808 KB |
testcase_05 | AC | 4 ms
7,680 KB |
testcase_06 | AC | 5 ms
7,680 KB |
testcase_07 | AC | 5 ms
7,680 KB |
testcase_08 | AC | 7 ms
7,936 KB |
testcase_09 | AC | 8 ms
8,364 KB |
testcase_10 | AC | 11 ms
8,960 KB |
testcase_11 | AC | 11 ms
8,832 KB |
testcase_12 | AC | 7 ms
8,192 KB |
testcase_13 | AC | 89 ms
18,980 KB |
testcase_14 | AC | 110 ms
21,516 KB |
testcase_15 | AC | 126 ms
24,292 KB |
testcase_16 | AC | 66 ms
20,636 KB |
testcase_17 | AC | 116 ms
22,396 KB |
testcase_18 | AC | 110 ms
24,588 KB |
testcase_19 | AC | 144 ms
30,084 KB |
testcase_20 | AC | 111 ms
23,352 KB |
testcase_21 | AC | 121 ms
23,908 KB |
testcase_22 | AC | 145 ms
26,560 KB |
testcase_23 | AC | 184 ms
31,188 KB |
testcase_24 | AC | 185 ms
31,196 KB |
testcase_25 | AC | 187 ms
31,192 KB |
testcase_26 | AC | 193 ms
31,136 KB |
testcase_27 | AC | 188 ms
31,248 KB |
testcase_28 | AC | 185 ms
31,216 KB |
testcase_29 | AC | 190 ms
31,160 KB |
testcase_30 | AC | 201 ms
31,224 KB |
testcase_31 | AC | 191 ms
31,140 KB |
testcase_32 | AC | 183 ms
31,100 KB |
testcase_33 | AC | 5 ms
7,680 KB |
testcase_34 | AC | 74 ms
20,720 KB |
testcase_35 | AC | 141 ms
52,064 KB |
testcase_36 | AC | 122 ms
18,764 KB |
testcase_37 | AC | 5 ms
7,808 KB |
testcase_38 | AC | 41 ms
7,808 KB |
testcase_39 | AC | 171 ms
63,080 KB |
testcase_40 | AC | 132 ms
29,448 KB |
ソースコード
/* -*- coding: utf-8 -*- * * 1983.cc: No.1983 [Cherry 4th Tune C] 南の島のマーメイド - yukicoder */ #include<cstdio> #include<vector> #include<stack> #include<algorithm> #include<utility> using namespace std; /* constant */ const int MAX_N = 200000; /* typedef */ typedef pair<int,int> pii; typedef vector<int> vi; typedef vector<bool> vb; typedef vector<vi> vvi; typedef vector<pii> vpii; typedef stack<int> si; struct UFT { vector<int> links, ranks, sizes; UFT() {} void init(int n) { links.resize(n); for (int i = 0; i < n; i++) links[i] = i; ranks.assign(n, 1); sizes.assign(n, 1); } int root(int i) { int i0 = i; while (links[i0] != i0) i0 = links[i0]; return (links[i] = i0); } int rank(int i) { return ranks[root(i)]; } int size(int i) { return sizes[root(i)]; } bool same(int i, int j) { return root(i) == root(j); } int merge(int i0, int i1) { int r0 = root(i0), r1 = root(i1), mr; if (r0 == r1) return r0; if (ranks[r0] == ranks[r1]) { links[r1] = r0; sizes[r0] += sizes[r1]; ranks[r0]++; mr = r0; } else if (ranks[r0] > ranks[r1]) { links[r1] = r0; sizes[r0] += sizes[r1]; mr = r0; } else { links[r0] = r1; sizes[r1] += sizes[r0]; mr = r1; } return mr; } }; /* global variables */ vi nbrs[MAX_N]; UFT uft; /* subroutines */ void bcc_visit(const vi *nbrs, int v, int u, vpii& brdg, vvi& tecomp, si& roots, si& S, vb& inS, vi& num, int& time) { num[v] = ++time; S.push(v); inS[v] = true; roots.push(v); const vi& nbrv = nbrs[v]; for (vi::const_iterator vit = nbrv.begin(); vit != nbrv.end(); vit++) { const int& w = *vit; if (num[w] == 0) bcc_visit(nbrs, w, v, brdg, tecomp, roots, S, inS, num, time); else if (u != w && inS[w]) while (num[roots.top()] > num[w]) roots.pop(); } if (v == roots.top()) { brdg.push_back(pii(u, v)); tecomp.push_back(vi()); for (;;) { int w = S.top(); S.pop(); inS[w] = false; tecomp.back().push_back(w); if (v == w) break; } roots.pop(); } } void calc_bcc(const int n, const vi *nbrs, vpii& brdg, vvi& tecomp) { vi num(n); vb inS(n); si roots, S; int time = 0; for (int u = 0; u < n; u++) if (num[u] == 0) { bcc_visit(nbrs, u, n, brdg, tecomp, roots, S, inS, num, time); brdg.pop_back(); } } bool visited[MAX_N]; int depth[MAX_N], low[MAX_N], parents[MAX_N]; int aps[MAX_N], apn; void getArticulationPoints(int i, int d) { visited[i] = true; depth[i] = low[i] = d; int childCount = 0; bool isArticulation = false; vi &nbri = nbrs[i]; for (vi::iterator vit = nbri.begin(); vit != nbri.end(); vit++) { int &j = *vit; if (! visited[j]) { parents[j] = i; getArticulationPoints(j, d + 1); childCount++; if (low[j] >= depth[i]) isArticulation = true; low[i] = min(low[i], low[j]); } else if (j != parents[i]) low[i] = min(low[i], depth[j]); } if ((parents[i] >= 0 && isArticulation) || (parents[i] < 0 && childCount > 1)) aps[i] = true, apn++; } /* main */ int main() { int n, m, qn; scanf("%d%d%d", &n, &m, &qn); for (int i = 0; i < m; i++) { int a, b; scanf("%d%d", &a, &b); a--, b--; nbrs[a].push_back(b); nbrs[b].push_back(a); } vpii brdgs; vvi tcmp; calc_bcc(n, nbrs, brdgs, tcmp); uft.init(n); for (auto e: brdgs) uft.merge(e.first, e.second); while (qn--) { int x, y; scanf("%d%d", &x, &y); x--, y--; if (uft.same(x, y)) puts("Yes"); else puts("No"); } return 0; }