QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#707385 | #8333. Gift | windStrider# | WA | 0ms | 3516kb | C++20 | 1.7kb | 2024-11-03 15:46:19 | 2024-11-03 15:46:19 |
Judging History
answer
#include <bits/stdc++.h>
using pii = std::pair<int, int>;
using ll = long long;
int main()
{
int n;
std::cin >> n;
std::vector<std::vector<int>> adj(n + 1);
std::vector<int> deg(n + 1), tmp;
int cnt4 = 0, ind = -1;
for (int i = 0; i < n; ++i)
{
int l, r;
std::cin >> l >> r;
adj[l].emplace_back(r);
adj[r].emplace_back(l);
++deg[l], ++deg[r];
if (deg[l] == 5) ind = l;
if (deg[r] == 5) ind = r;
if (deg[l] == 4) ++cnt4;
if (deg[r] == 4) ++cnt4;
}
tmp = deg;
std::vector<bool> vis;
std::queue<int> q;
for (int i = 1; i <= n; ++i) if (tmp[i] == 1) q.emplace(i);
while (q.size())
{
int u = q.front();
q.pop();
for (int to : adj[u])
{
--tmp[to];
if (tmp[to] == 1) q.emplace(to);
}
tmp[u] = 0;
}
std::vector<bool> loop(n + 1);
ll ans = 0;
for (int i = 1; i <= n; ++i) if (tmp[i] != 0) loop[i] = 1;
for (int i = 1; i <= n; ++i)
{
for (int u : adj[i])
{
if (loop[i] && loop[u])
{
if (ind != -1 && i != ind && i != ind) continue;
// std::cout << cnt4 << "\n";
if (deg[i] == 4) --cnt4;
if (deg[u] == 4) --cnt4;
--deg[i];
--deg[u];
ans += n - cnt4;
++deg[i];
++deg[u];
if (deg[i] == 4) ++cnt4;
if (deg[u] == 4) ++cnt4;
}
}
}
std::cout << ans << "\n";
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3516kb
input:
6 1 2 1 3 1 4 1 5 1 6 2 3
output:
10
result:
ok 1 number(s): "10"
Test #2:
score: -100
Wrong Answer
time: 0ms
memory: 3508kb
input:
3 1 3 3 2 2 1
output:
18
result:
wrong answer 1st numbers differ - expected: '9', found: '18'