QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#650317 | #8335. Fast Hash Transform | Mcggvc# | TL | 0ms | 0kb | C++20 | 1.5kb | 2024-10-18 14:35:27 | 2024-10-18 14:35:30 |
answer
#include<bits/stdc++.h>
using namespace std;
#define ing long long
const int N = 100010;
int n;
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++;
}
bool 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};
return true;
}
vis[tx]=true;
if(dfs(tx,x)){
huan[++t]={x,tx};
return true;
}
}
return false;
}
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