QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#708623 | #8333. Gift | xggx | WA | 0ms | 3660kb | C++20 | 1.3kb | 2024-11-04 01:04:14 | 2024-11-04 01:04:16 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 1e5 + 10;
int n;
vector<vector<int>> adj;
bool vis[N];
int fa[N];
vector<int> huan;
bool flag = 0;
void dfs(int x) {
if (vis[x] || flag) return;
vis[x] = 1;
for (auto v : adj[x]) {
if (!vis[v]){
fa[v] = x;
dfs(v);
}
else {
flag = 1;
int cur = fa[v];
while (v != cur) {
huan.push_back(cur);
cur = fa[cur];
}
huan.push_back(v);
}
}
}
int main() {
ios::sync_with_stdio(false);
cin.tie(0); cout.tie(0);
// #ifndef ONLINE_JUDGE
// freopen("in.in", "r", stdin);
// #endif
cin >> n;
adj.resize(n);
for (int i = 0; i < n; i++) {
int x, y;
cin >> x >> y;
x--, y--;
adj[x].push_back(y);
adj[y].push_back(x);
}
dfs(0);
ll ans = 0;
bool flag = 0;
for (auto u : huan) {
if ((int)adj[u].size() == 5) {
flag = 1;
break;
}
}
if (flag) {
ans = 2 * (n - 1);
} else {
ans = (int)huan.size() * n;
}
cout << ans;
return 0;
}
/*
6
1 2
1 3
1 4
1 5
1 6
2 3
*/
详细
Test #1:
score: 100
Accepted
time: 0ms
memory: 3580kb
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: 3660kb
input:
3 1 3 3 2 2 1
output:
3
result:
wrong answer 1st numbers differ - expected: '9', found: '3'