QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#657465 | #8333. Gift | the_foo# | WA | 1ms | 5768kb | C++20 | 2.1kb | 2024-10-19 14:48:59 | 2024-10-19 14:49:01 |
Judging History
answer
#include <bits/stdc++.h>
#define endl '\n'
#define int long long
using namespace std;
int n,d[100005],d5,d4;
struct EDGE
{
int u,v,next;
bool g;
}edge[200005];
int head[100005],cnt=-1;
void addedge(int u,int v)
{
edge[++cnt].u=u;
edge[cnt].v=v;
edge[cnt].next=head[u];
head[u]=cnt;
}
int id,dfn[100005],low[100005];
bool vis[200005];
void tarjan(int u)
{
dfn[u]=low[u]=++id;
for(int i=head[u];i!=-1;i=edge[i].next) {
int v=edge[i].v;
if(vis[i])continue;
vis[i]=1;
vis[i^1]=1;
if(dfn[v]==0)
{
tarjan(v);
low[u]=min(low[u],low[v]);
if(low[v]>dfn[u])
{
edge[i].g=1;
edge[i^1].g=1;
}
}
else low[u]=min(low[u],dfn[v]);
}
}
void solve() {
cin >> n;
memset(head,-1,sizeof(head));
for(int i=1;i<=n;i++)
{
int u,v;
cin>>u>>v;
addedge(u,v);
addedge(v,u);
d[u]++;
d[v]++;
}
for(int i=1;i<=n;i++)
{
if(d[i]==5)d5++;
if(d[i]==4)d4++;
}
tarjan(1);
if(d5==2)cout<<n-2-d4<<endl;
else if(d5==1)
{
int ans=0;
for(int i=0;i<=2*n;i+=2)
{
int u=edge[i].u,v=edge[i].v,g=edge[i].g;
if(g)continue;
if(d[v]==5)swap(u,v);
if(d[u]!=5)continue;
if(d[u]==1||d[v]==1)continue;
if(d[v]==4)ans+=n-1-d4+1;
else ans+=n-1-d4;
}
cout<<ans<<endl;
}
else
{
int ans=0;
for(int i=0;i<=2*n;i+=2)
{
int u=edge[i].u,v=edge[i].v,g=edge[i].g;
if(g)continue;
if(d[u]==1||d[v]==1)continue;
if(d[u]==4&&d[v]==4)ans+=n-d4+2;
else if(d[u]==4||d[v]==4)ans+=n-d4+1;
else ans+=n-d4;
}
cout<<ans<<endl;
}
}
signed main() {
ios::sync_with_stdio(0);
cin.tie(0);
int t = 1;
//cin >> t;
while (t--) {
solve();
}
}
详细
Test #1:
score: 100
Accepted
time: 1ms
memory: 5768kb
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: 5664kb
input:
3 1 3 3 2 2 1
output:
12
result:
wrong answer 1st numbers differ - expected: '9', found: '12'