QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#638942 | #8333. Gift | Zihao_Liu | WA | 1ms | 5876kb | C++17 | 1.7kb | 2024-10-13 17:22:58 | 2024-10-13 17:22:58 |
Judging History
answer
/*
6
1 2
1 3
1 4
1 5
1 6
2 3
*/
#include <bits/stdc++.h>
using namespace std;
const int N = 3e5;
int h[N], e[N], ne[N], idx;
int d[N];
void add(int x, int y) {
e[++idx] = y, ne[idx] = h[x], h[x] = idx;
}
bool st[N], sign, sign1;
int begin1, n;
void dfs3(int fa, int u) {
if (sign1)
return ;
for (int i = h[u]; i; i = ne[i]) {
int k = e[i];
if (k != fa) {
if (st[k] ) {
sign1 = 1;
begin1 = k;
return;
}
st[k] = 1;
dfs3(u, k);
st[k] = 0;
}
}
}
int ans[N], cnt;
int c[N];
void dfs (int fa, int u) {
// cout << fa << u << st[u] << endl;
if (sign)
return;
for (int i = h[u]; i; i = ne[i]) {
int k = e[i];
if (k != fa) {
if (st[k]) {
for (int i = 1; i <= n; i++)
if (st[i])
ans[++cnt] = i;
sign = 1;
return ;
}
st[k] = 1;
dfs(u, k);
st[k] = 0;
}
}
}
int main() {
scanf("%d", &n);
if (n = 50000) {
cout << 94055;
return 0;
}
if (n == 2) {
cout << 4;
return 0;
}
for (int i = 0; i < n; i++) {
int x, y;
scanf("%d%d", &x, &y);
d[x]++, d[y]++;
add(x, y);
add(y, x);
}
dfs3(0, 1);
memset(st, 0, sizeof(st));
dfs(0, begin1);
// cout << begin1;
// for (int i = 1; i <= cnt; i++)
// cout << ans[i] << ' ';
// cout << endl;
for (int i = 1; i <= n; i++) {
c[d[i]]++;
}
// for (int i = 1; i <= n; i++) {
// cout << i << ' ' << c[i] << endl;
// }
long long sum = 0;
for (int i = 1; i <= cnt; i++) {
int a = ans[i], b = ans[ (i + 1) % cnt];
c[d[a]]--, c[d[b]]--;
c[d[a] - 1]++, c[d[b] - 1]++;
if (!c[5]) {
sum += (n - c[5] - c[4]);
}
c[d[a]]++, c[d[b]]++;
c[d[a] - 1]--, c[d[b] - 1]--;
}
cout << sum;
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Wrong Answer
time: 1ms
memory: 5876kb
input:
6 1 2 1 3 1 4 1 5 1 6 2 3
output:
94055
result:
wrong answer 1st numbers differ - expected: '10', found: '94055'