QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#657465#8333. Giftthe_foo#WA 1ms5768kbC++202.1kb2024-10-19 14:48:592024-10-19 14:49:01

Judging History

你现在查看的是最新测评结果

  • [2024-10-19 14:49:01]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:5768kb
  • [2024-10-19 14:48:59]
  • 提交

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'