QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#739302 | #8333. Gift | zerocloud01# | WA | 1ms | 3608kb | C++20 | 2.3kb | 2024-11-12 21:23:09 | 2024-11-12 21:23:11 |
Judging History
answer
#include<bits/stdc++.h>
#define int long long
#define PII pair<int,int>
#define x first
#define y second
using namespace std;
const int N = 1e5 + 10;
int n;
bool op;
bitset<N> vis;
vector<int> a[N],t[N];
vector<int> ci,stp;
void dfs(int lp,int p)
{
for(auto &i : a[p])
{
if(i == lp) continue;
if(vis[i])
{
ci = stp;
return ;
}
vis[i] = true;
stp.push_back(i);
dfs(p,i);
vis[i] = false;
stp.pop_back();
}
}
void dfs2(int lp,int p)
{
for(auto &i : a[p])
{
if(i == lp)
{
op = true;
return;
}
if(vis[i]) continue;
vis[i] = true;
dfs2(p,i);
}
}
signed main(void)
{
cin.tie(0), cout.tie(0), ios::sync_with_stdio(false);
cin >> n;
int ans = 0;
for(int i=1;i<=n;++i)
{
int x,y; cin >> x >> y;
a[x].push_back(y), a[y].push_back(x);
t[x].push_back(i);
}
if(n == 2)
{
cout << 4 << '\n';
return 0;
}
dfs(0,1);
vis.reset();
dfs2(0,1);
if(op)
{
cout << (n*2) << '\n';
return 0;
}
stp.clear();
for(int i=1;i<=n;++i) if(a[i].size() >= 5) stp.push_back(i);
//for(auto &i : ci) cout << i << ' ';
if(stp.size() == 1) ans = (n-1)*2;
else if(stp.size() == 2)
{
//sort(ci.begin(),ci.end());
//for(auto &i : a[stp[0]])
//{
// if(i == stp[1])
// {
// if(lower_bound(ci.begin(),ci.end(),stp[0]) != ci.end() && lower_bound(ci.begin(),ci.end(),stp[1]) != ci.end()) ans =
// }
//}
ans = (n-2);
//ans += (n-stp.size())*ci.size();
}
else
{
//stp = ci;
stp.clear();
for(int i=1;i<=n;++i) if(a[i].size() >= 4) stp.push_back(i);
sort(ci.begin(),ci.end());
for(auto &i : stp)
{
if(lower_bound(ci.begin(),ci.end(),i) != ci.end()) ans += 2;
//cout << i << ' ';
}
//puts("");
//cout << ans << ' ' << stp.size() << '\n';
ans += (n-stp.size())*ci.size();
}
cout <<ans <<'\n';
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Wrong Answer
time: 1ms
memory: 3608kb
input:
6 1 2 1 3 1 4 1 5 1 6 2 3
output:
12
result:
wrong answer 1st numbers differ - expected: '10', found: '12'