QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#650418#8335. Fast Hash TransformMcggvc#TL 0ms0kbC++201.7kb2024-10-18 15:04:302024-10-18 15:04:30

Judging History

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

  • [2024-10-18 15:04:30]
  • 评测
  • 测评结果:TL
  • 用时:0ms
  • 内存:0kb
  • [2024-10-18 15:04:30]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;

#define ing long long

const int N = 100010;

int n;
int bj;

struct EDGE{
    int to;
    int next;
}edge[N<<1];
int head[N],cnt;

int t;
pair<int,int> huan[N];

int in[N];
int num[N];

int ans;

bool vis[N];

void init(){
    cnt=0;
    for(int i=1;i<=n;i++)
        head[i]=-1;
}

void Add_Edge(int u,int v){
    edge[cnt].to=v;
    edge[cnt].next=head[u];
    head[u]=cnt++;    
}

int viscnt;

int dfs(int x,int fa){
    viscnt++;
    for(int i=head[x];~i;i=edge[i].next){
        int tx=edge[i].to;
        if(tx==fa)
            continue;
        if(vis[tx]){
            huan[++t]={x,tx};
            bj=tx;
            return 1;
        }
        vis[tx]=true;
        int a=dfs(tx,x);
        if(a==0)
            continue;
        if(a==1){
            if(tx==bj)
                return 2;
            huan[++t]={x,tx};
            return 1;
        }
        if(a==2)
            return 2;
    }
    return 0;
}

signed main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cin>>n;
    init();
    for(int i=1;i<=n;i++){
        int u,v;
        cin>>u>>v;
        in[u]++;
        in[v]++;
        Add_Edge(u,v);
        Add_Edge(v,u);
    }
    vis[1]=true;
    dfs(1,0);
    for(int i=1;i<=n;i++){
        num[in[i]]++;
    }
    for(int i=1;i<=t;i++){
        int u=huan[i].first;
        int v=huan[i].second;
        num[in[u]]--;
        num[in[v]]--;
        num[in[u]-1]++;
        num[in[v]-1]++;
        if(!num[5])
            ans=ans+num[1]+num[2]+num[3];
        num[in[u]-1]--;
        num[in[v]-1]--;
        num[in[u]]++;
        num[in[v]]++;
    }
    cout<<ans<<" ";
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Time Limit Exceeded

input:

3 5 1
1 4 0 0 51966
1 60 0 0 0
1 0 0 16 15
0 1 1 771
0 2 2 32368
0 3 3 0
1 2 2 0 0 15 61 1 4095 46681
0 1 3 2023

output:


result: