提出 #73543634
ソースコード 拡げる
#include<bits/stdc++.h>
#define LL long long
#define PLL pair<LL, LL>
#define PII pair<int, int>
#define PLI pair<LL, int>
#define int LL
using namespace std;
int n, ncnt = 0;
vector<PII> x, y, z;
vector<vector<int> > g;
vector<int> dfn, low, bel;
stack<int> st;
vector<bool> vis;
void tarjan(int u = 1) {
dfn[u] = low[u] = ++ncnt;
st.push(u); vis[u] = 1;
// cout << u << " u\n";
for (auto v : g[u]) {
// cout << u << " " << v << " v\n";
if (!dfn[v]) {
tarjan(v);
low[u] = min(low[u], low[v]);
} else if (vis[v]) {
low[u] = min(low[u], dfn[v]);
}
}
if (dfn[u] == low[u]) {
while (1) {
int id = st.top(); st.pop();
bel[id] = u; vis[id] = 0;
if (id == u) break;
}
}
}
inline void solve() {
cin >> n;
while (!st.empty()) st.pop();
x.clear(); y.clear(); z.clear(); ncnt = 0; vis.clear();
dfn.clear(); low.clear(); bel.clear(); g.clear();
x.resize(n + 1); y.resize(n + 1); z.resize(n + 1); vis.resize(n + 1);
dfn.resize(n + 1); low.resize(n + 1); bel.resize(n + 1);
for (int i = 1; i <= n; i++) {
cin >> x[i].first >> y[i].first >> z[i].first;
x[i].second = y[i].second = z[i].second = i;
}
sort(x.begin() + 1, x.end());
sort(y.begin() + 1, y.end());
sort(z.begin() + 1, z.end());
reverse(x.begin() + 1, x.end());
reverse(y.begin() + 1, y.end());
reverse(z.begin() + 1, z.end());
g.resize(n + 1);
for (int i = 1; i < n; i++) {
g[x[i].second].push_back(x[i + 1].second);
if (x[i].first == x[i + 1].first) g[x[i + 1].second].push_back(x[i].second);
g[y[i].second].push_back(y[i + 1].second);
if (y[i].first == y[i + 1].first) g[y[i + 1].second].push_back(y[i].second);
g[z[i].second].push_back(z[i + 1].second);
if (z[i].first == z[i + 1].first) g[z[i + 1].second].push_back(z[i].second);
}
tarjan(x[1].second);
// for (int i = 1; i <= n; i++) {
// cout << bel[i] << " bel\n";
//// if (!dfn[i]) tarjan(i);
// }
int ans = 0;
for (int i = 1; i <= n; i++) {
ans += (bel[i] == bel[1]);
}
cout << ans << "\n";
}
signed main() {
ios::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr);
int t = 1;
cin >> t;
while (t--) solve();
return 0;
}
提出情報
| 提出日時 | |
|---|---|
| 問題 | C - Strong Surname |
| ユーザ | C202627yehan |
| 言語 | C++23 (GCC 15.2.0) |
| 得点 | 0 |
| コード長 | 2195 Byte |
| 結果 | WA |
| 実行時間 | 160 ms |
| メモリ | 57860 KiB |
ジャッジ結果
| セット名 | Sample | All | ||||||
|---|---|---|---|---|---|---|---|---|
| 得点 / 配点 | 0 / 0 | 0 / 600 | ||||||
| 結果 |
|
|
| セット名 | テストケース |
|---|---|
| Sample | 00_sample_01.txt |
| All | 00_sample_01.txt, hand-12.txt, hand-13.txt, hand-14.txt, hand-15.txt, hand-16.txt, hand-17.txt, hand-18.txt, hand-19.txt, hand-20.txt, hand-21.txt, hand-22.txt, random-01.txt, random-02.txt, random-03.txt, random-04.txt, random-05.txt, random-06.txt, random-07.txt, random-08.txt, random-09.txt, random-10.txt, random-11.txt |
| ケース名 | 結果 | 実行時間 | メモリ |
|---|---|---|---|
| 00_sample_01.txt | AC | 1 ms | 3556 KiB |
| hand-12.txt | WA | 63 ms | 3672 KiB |
| hand-13.txt | WA | 99 ms | 9432 KiB |
| hand-14.txt | WA | 160 ms | 57860 KiB |
| hand-15.txt | WA | 155 ms | 54600 KiB |
| hand-16.txt | AC | 147 ms | 53944 KiB |
| hand-17.txt | AC | 107 ms | 9604 KiB |
| hand-18.txt | WA | 106 ms | 9624 KiB |
| hand-19.txt | AC | 97 ms | 30716 KiB |
| hand-20.txt | WA | 105 ms | 9552 KiB |
| hand-21.txt | WA | 106 ms | 9560 KiB |
| hand-22.txt | AC | 44 ms | 9416 KiB |
| random-01.txt | AC | 31 ms | 3544 KiB |
| random-02.txt | WA | 52 ms | 3536 KiB |
| random-03.txt | AC | 71 ms | 4268 KiB |
| random-04.txt | AC | 99 ms | 8788 KiB |
| random-05.txt | AC | 116 ms | 16464 KiB |
| random-06.txt | AC | 129 ms | 29640 KiB |
| random-07.txt | AC | 159 ms | 55184 KiB |
| random-08.txt | AC | 153 ms | 55200 KiB |
| random-09.txt | AC | 159 ms | 55248 KiB |
| random-10.txt | AC | 160 ms | 55124 KiB |
| random-11.txt | AC | 152 ms | 55112 KiB |