QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#660388 | #8333. Gift | Komorebie# | WA | 27ms | 18128kb | C++17 | 2.7kb | 2024-10-20 10:53:34 | 2024-10-20 10:53:34 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
#define maxn 200005
int n;
int x, y, cnt, st[maxn], tot, o, t;
int ans = 0;
vector<int> to[maxn];
bool flat[maxn];
bool dfs(int x, int fa)
{
st[++tot] = x;
flat[x] = 1;
for (int i = 0; i < to[x].size(); i++) {
if (fa == to[x][i]) continue;
if (flat[to[x][i]]) {
o = to[x][i];
return 1;
}
else if (dfs(to[x][i], x)) {
return 1;
}
}
--tot;
return 0;
}
queue<int> q;
queue<int> p;
int main()
{
ios::sync_with_stdio(false);
cin.tie(0);
cin >> n;
for (int i = 1; i <= n; i++) {
cin >> x >> y;
to[x].push_back(y);
to[y].push_back(x);
}
bool flag = 0;
for (int i = 1; i <= n; i++) {
if (to[i].size() >= 6) {
cout << 0 << endl;
return 0;
}
else {
if (to[i].size() == 5) {
q.push(i);
}
else {
if (to[i].size() != 4) cnt++;
}
}
}
dfs(1, 0);
if (q.size() > 2) {
cout << 0 << endl;
return 0;
}
if (!q.empty()) { // 有5度的点的话,删除的边必须包含所有的该点
t = -1;
int i;
for (i = tot;; i--) {
if (to[st[i]].size() == 5) {
p.push(st[i]);
t = i;
}
if (st[i] == o) break;
}
if (p.size() != q.size()) { // 表示的是5度的点在环外
cout << 0 << endl;
return 0;
}
if (p.size() == 1) {//如果5度点只有一个
if (st[t] == o) st[t - 1] = st[tot];
if (t = tot) st[t + 1] = o;
if (to[st[t + 1]].size() == 4) ans++;
if (to[st[t - 1]].size() == 4) ans++;
cout << ans + cnt * 2 << endl;
return 0;
}
else {//5度点有两个
x = st[t];
for(int i=0;i<to[x].size();i++){
y=to[x][i];
if(to[y].size()==5){
cout<<cnt<<endl;
return 0;
}
}
cout<<0<<endl;
return 0;
}
}
else {
for (int i = tot; st[i] != o; i--) { // 枚举的是删去 st[i] - st[i-1] 这条边
if (to[st[i]].size() == 4) ans++;
if (to[st[i - 1]].size() == 4) ans++;
ans += cnt;
}
if (to[st[tot]].size() == 4) ans++;
if (to[o].size() == 4) ans++;
ans += cnt;
cout << ans<<endl;
}
return 0;
}
详细
Test #1:
score: 100
Accepted
time: 2ms
memory: 8152kb
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: 1ms
memory: 8436kb
input:
3 1 3 3 2 2 1
output:
9
result:
ok 1 number(s): "9"
Test #3:
score: 0
Accepted
time: 2ms
memory: 8384kb
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: -100
Wrong Answer
time: 27ms
memory: 18128kb
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:
1410065408
result:
wrong answer 1st numbers differ - expected: '10000000000', found: '1410065408'