QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#707514 | #8333. Gift | windStrider# | WA | 46ms | 11052kb | C++20 | 2.1kb | 2024-11-03 16:18:54 | 2024-11-03 16:19:05 |
Judging History
answer
#include <bits/stdc++.h>
using pii = std::pair<int, int>;
using ll = long long;
#define int long long
signed main()
{
int n;
std::cin >> n;
// std::set<pii> s;
std::vector<std::vector<int>> adj(n + 1);
std::vector<pii> edg;
std::vector<int> deg(n + 1), tmp;
int cnt4 = 0;
std::vector<int> ind;
// bool flag = 0;
for (int i = 0; i < n; ++i)
{
int l, r;
std::cin >> l >> r;
edg.emplace_back(l, r);
// if (s.count({ l, r }) || s.count({ r, l }))
// {
// flag = 1;
// }
adj[l].emplace_back(r);
adj[r].emplace_back(l);
++deg[l], ++deg[r];
if (deg[l] == 5) ind.emplace_back(l);
if (deg[r] == 5) ind.emplace_back(r);
if (deg[l] == 4) ++cnt4;
if (deg[r] == 4) ++cnt4;
}
// if (flag)
// {
// std::cout << n << "\n";
// return 0;
// }
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 j = 0; j < edg.size(); ++j)
{
auto [i, u] = edg[j];
if (loop[i] && loop[u])
{
if (ind.size() == 1 && i != ind[0] && u != ind[0]) continue;
if (ind.size() == 2)
if (!(i == ind[0] && u == ind[1] || i == ind[1] && u == ind[0])) 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;
}
详细
Test #1:
score: 100
Accepted
time: 0ms
memory: 3664kb
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: 0
Accepted
time: 0ms
memory: 3624kb
input:
3 1 3 3 2 2 1
output:
9
result:
ok 1 number(s): "9"
Test #3:
score: 0
Accepted
time: 1ms
memory: 3988kb
input:
2332 1648 909 1676 2122 1644 1981 1106 1131 1785 239 223 618 335 1662 424 1775 889 1684 1589 52 1406 1747 1600 302 790 2056 1742 464 1706 541 1145 779 2316 833 1645 1439 859 438 1337 136 746 1565 436 1730 2079 2145 1583 1940 917 1549 1863 507 1266 367 1890 2230 13 2113 492 2109 120 1122 815 1111 134...
output:
5438224
result:
ok 1 number(s): "5438224"
Test #4:
score: 0
Accepted
time: 46ms
memory: 11052kb
input:
100000 46198 33056 80285 88339 88963 925 43203 66233 13618 35880 19864 76475 90021 73072 3202 63653 41571 83067 22067 98768 10753 16653 32856 85797 3483 2064 46659 9486 23290 82179 97966 23617 81566 7334 81774 76138 10959 75816 93471 12058 97260 66262 85541 78476 67864 87220 8607 52245 38957 67603 7...
output:
10000000000
result:
ok 1 number(s): "10000000000"
Test #5:
score: -100
Wrong Answer
time: 44ms
memory: 11032kb
input:
100000 54772 14057 70680 93042 84913 63248 79360 97774 84190 60881 31137 29439 99037 81117 38579 32074 31206 19912 70774 23067 60717 79586 83847 43306 55351 50174 32566 70092 22736 92279 55916 20029 41571 63309 33143 65579 35033 3869 50038 4275 59533 25348 53092 32698 27604 14678 6802 18226 23173 96...
output:
9999600000
result:
wrong answer 1st numbers differ - expected: '5017400000', found: '9999600000'