QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#645604 | #8333. Gift | yihang_01# | WA | 1ms | 3688kb | C++20 | 1.6kb | 2024-10-16 19:09:40 | 2024-10-16 19:09:42 |
Judging History
answer
#include <bits/stdc++.h>
using std::cin;
using std::cout;
using std::string;
using ll = long long;
using ull = unsigned long long;
using uint = unsigned int;
const int N = 1e5 + 10;
int n;
std::vector<int> g[N];
int d[N];
bool st[N];
int huan;
std::vector<int> path;
bool ok = false;
int cnt[N];
void dfs(int u, int fa) {
if (ok) return;
st[u] = true;
for (auto v: g[u]) {
if (v == fa) continue;
if (st[v]) {
huan = v;
path.push_back(v);
return;
}
dfs(v, u);
if (huan) {
path.push_back(v);
if (u == huan) huan = 0;
ok = true;
return;
}
}
st[u] = false;
}
void solve() {
cin >> n;
for (int i = 1; i <= n; i ++ ) {
int a, b;
cin >> a >> b;
g[a].push_back(b);
g[b].push_back(a);
d[a] ++, d[b] ++;
}
for (int i = 1; i <= n; i ++ ) {
cnt[d[i]] ++;
}
dfs(1, -1);
long long ans = 0;
for (int i = 1; i < path.size(); i ++ ) {
int a = path[i - 1], b = path[i];
cnt[d[a]] --, cnt[d[b]] --;
cnt[d[a] - 1] ++, cnt[d[b] - 1] ++;
int t = cnt[1] + cnt[2] + cnt[3];
// cout << "t:" << t << "\n";
ans += t;
cnt[d[a]] ++, cnt[d[b]] ++;
cnt[d[a] - 1] --, cnt[d[b] - 1] --;
}
cout << ans << "\n";
}
int main() {
std::ios::sync_with_stdio(false);
cin.tie(0);
int T = 1;
//cin >> T;
while (T --)
{
solve();
}
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 3688kb
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: 1ms
memory: 3608kb
input:
3 1 3 3 2 2 1
output:
6
result:
wrong answer 1st numbers differ - expected: '9', found: '6'