QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#650354 | #8335. Fast Hash Transform | Mcggvc# | TL | 0ms | 0kb | C++20 | 1.7kb | 2024-10-18 14:47:22 | 2024-10-18 14:47:23 |
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[10];
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 dfs(int x,int fa){
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