QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#121667 | #852. Jellyfish | karuna# | WA | 101ms | 6620kb | C++17 | 1.6kb | 2023-07-08 17:05:32 | 2023-07-08 17:05:36 |
Judging History
answer
#include <bits/stdc++.h>
#define ff first
#define ss second
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int M = 101010;
int n;
vector<int> g[M];
int par[M], ln[M], dn;
bool cyc[M];
void dfs(int p, int v) {
ln[v] = ++dn;
for (int x : g[v]) {
if (p == x) continue;
if (!ln[x]) {
par[x] = v;
dfs(v, x);
}
else if (ln[x] < ln[v]) {
for (int y = v; y != x; y = par[y])
cyc[y] = 1;
cyc[x] = 1;
}
}
}
int dp[M];
void dfs2(int p, int v) {
dp[v] = 0;
for (int x : g[v]) if (p != x && !cyc[x]) {
dfs2(v, x);
dp[v] += dp[x];
}
if (p != v)
dp[v] = max(dp[v], 1);
}
int main() {
cin.tie(0); ios_base::sync_with_stdio(0);
int t; cin >> t;
while (t--) {
cin >> n;
for (int i = 0; i < n; i++) {
int u, v; cin >> u >> v;
g[u].push_back(v);
g[v].push_back(u);
}
dfs(0, 1);
int ans = 0, cnt = 0;
for (int i = 1; i <= n; i++) {
if (cyc[i]) {
dfs2(i, i);
if (dp[i] != 0)
ans += dp[i];
else
++cnt;
}
}
cout << max(3, ans + min(2, cnt)) << '\n';
dn = 0;
for (int i = 1; i <= n; i++) {
g[i].clear();
par[i] = 0;
cyc[i] = 0;
ln[i] = 0;
dp[i] = 0;
}
}
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 2ms
memory: 5916kb
input:
2 6 1 2 2 3 3 4 4 1 2 5 2 6 4 1 2 2 3 3 4 4 1
output:
4 3
result:
ok 2 number(s): "4 3"
Test #2:
score: -100
Wrong Answer
time: 101ms
memory: 6620kb
input:
85665 6 3 2 4 1 4 6 2 1 2 6 5 1 7 6 2 6 3 5 1 1 2 2 4 4 7 3 7 7 6 1 6 7 1 4 1 3 7 5 5 3 4 2 7 6 2 7 4 7 5 3 1 3 4 2 5 1 4 7 7 2 2 6 5 4 5 6 5 1 3 1 4 6 7 3 5 3 1 3 7 3 2 5 1 5 4 4 6 7 4 5 4 1 3 6 3 7 6 7 6 1 2 1 7 5 3 7 3 1 4 6 2 6 3 2 3 4 3 7 2 3 2 6 2 4 7 5 3 5 5 1 1 4 7 3 4 3 7 5 6 2 7 4 6 6 7 6 ...
output:
4 3 3 3 3 4 4 5 4 5 4 4 3 4 4 3 4 4 4 4 4 5 3 4 3 4 3 9 4 4 3 4 8 3 98 5 4 3 6 4 4 4 4 3 4 4 4 4 5 3 5 4 3 4 95 4 4 4 5 4 3 4 3 5 4 3 4 3 3 4 4 4 4 4 3 4 4 4 3 3 3 4 4 4 4 4 4 5 4 4 3 3 5 5 4 5 4 3 4 4 3 3 3 5 4 4 4 6 4 5 5 5 4 3 5 4 4 3 4 10 4 3 3 4 4 4 5 4 4 3 5 3 4 4 3 3 3 4 5 98 5 105 4 4 4 3 4 ...
result:
wrong answer 84th numbers differ - expected: '3', found: '4'