QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#697955 | #8333. Gift | ssx | WA | 2ms | 7676kb | C++20 | 2.4kb | 2024-11-01 16:34:35 | 2024-11-01 16:34:44 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ull unsigned long long
#define pll pair<ll, ll>
const int N = 3e5 + 50;
const int mod = 998244353;
vector<ll> e[N];
ll d[N], d1[N], n, cnt[10], st[N];
void solve()
{
ll ans = 0, sum = 0;
cin >> n;
ll x, y;
for (int i = 1; i <= n; i++)
{
cin >> x >> y;
e[x].push_back(y); e[y].push_back(x);
d[x] ++; d[y] ++;
}
queue<ll> q;
set<ll> s1;
for (int i = 1; i <= n; i++)
{
d1[i] = d[i];
if (d[i] > 4)
{
cnt[5] ++;
s1.insert(i);
}
else cnt[d[i]] ++;
if (d[i] == 1) q.push(i);
}
while (!q.empty())
{
auto tx = q.front();
st[tx] = 1;
q.pop();
for (auto it : e[tx])
{
d1[it] --;
if (d1[it] == 1) q.push(it);
}
}
set<ll> s;
for (int i = 1; i <= n; i++)
{
if (st[i] == 0) s.insert(i);
}
ll m1, m2, m3, m4;
for (int i = 1; i <= n; i++)
{
if (st[i] == 0)
{
for (auto it : e[i])
{
if (st[it] == 0)
{
//if(s1.size()-s1.count(i)-s1.count(it)!=0) continue;
m1 = d[i]; m2 = d[it];
//if (m1 > 4) m1 = 5;
//if (m2 > 4) m2 = 5;
cnt[m1] --; cnt[m2] --;
if (cnt[5] != 0) continue;
m3 = d[i] - 1; m4 = d[it] - 1;
//if (m3 > 4) m3 = 5;
//if (m4 > 4) m4 = 5;
cnt[m3] ++; cnt[m4] ++;
ans += cnt[1] + cnt[2] + cnt[3];
//cout << ans << '\n';
cnt[m1] ++; cnt[m2] ++;
cnt[m3] --; cnt[m4] --;
/*
ans += n - sum;
if (d[i] == 4) ans ++;
if (d[it] == 4) ans ++;
*/
}
}
}
}
cout << ans / 2;
}
int main()
{
ios::sync_with_stdio(false);
cin.tie(0);
ll T = 1;
//cin >> T;
while (T --)
{
solve();
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Wrong Answer
time: 2ms
memory: 7676kb
input:
6 1 2 1 3 1 4 1 5 1 6 2 3
output:
9
result:
wrong answer 1st numbers differ - expected: '10', found: '9'