QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#697554 | #8333. Gift | KOH-# | WA | 1ms | 5748kb | C++14 | 2.0kb | 2024-11-01 14:47:09 | 2024-11-01 14:47:10 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
template <typename T>
inline void read(T &x){
x=0;char ch=getchar();bool f=false;
while(!isdigit(ch)) f|=ch=='-',ch=getchar();
while(isdigit(ch)) x=(x<<1)+(x<<3)+(ch^48),ch=getchar();
x=f?-x:x;return;
}
template <typename T>
inline void print(T x){
if(x<0) putchar('-'),x=-x;
if(x>9) print(x/10);
putchar(x%10^48);return;
}
#define ll long long
const int N=1e5+3;
int head[N],to[N<<1],Next[N<<1],tot=1;
void Addedge(int u,int v){
to[++tot]=v,Next[tot]=head[u],head[u]=tot;
return;
}
int in[N],id[N],n;
bool Cmp(int x,int y){
return in[x]>in[y];
}
int lst[N],dfn[N],dnt;
bool ring[N];
void Dfs(int u){
dfn[u]=++dnt;
// cout<<u<<"???\n";
for(int i=head[u];i;i=Next[i]){
int v=to[i];
if(!dfn[v]){
lst[v]=i;
Dfs(v);
}
else if((i^1)!=lst[u]&&dfn[v]<dfn[u]){
// cout<<u<<" "<<v<<"???\n";
int now=u;ring[u]=true;
while(now!=v){
ring[now]=true;
now=to[lst[now]^1];
// cout<<now<<"???\n";
}
// cnt=dep[v]-dep[u]+1;
}
}
}
int t[N];
pair<int,int> e[N];
int main(){
// int T;read(T);
// while(T--){
read(n);
for(int i=1;i<=n;++i){
id[i]=i;int u,v;read(u),read(v);
Addedge(u,v),Addedge(v,u);
in[u]++,in[v]++;
e[i].first=u,e[i].second=v;
}
id[n]=n;
sort(id+1,id+n+1,Cmp);
Dfs(1);
bool fl=false;
ll ans=0;
// for(int i=1;i<=n;++i){
// if(ring[i]) cout<<i<<" ";
// }
for(int i=1;i<=n;++i) t[in[i]]++;
if(t[5]>=3) puts("0");
else{
for(int i=1;i<=n;++i){
int u=e[i].first,v=e[i].second;
if(ring[u]&&ring[v]){
t[in[u]]--,t[in[v]]--;
t[in[u]-1]++,t[in[v]-1]++;
if(!t[5]){
int res=t[1]+t[2]+t[3];
ans+=res;
}
t[in[u]]++,t[in[v]]++;
t[in[u]-1]--,t[in[v]-1]--;
}
}
print(ans);
}
// for(int i=1;i<=n;++i) id[i]=head[i]=fa[i]=dep[i]=in[i]=0,ring[i]=false;
// for(int i=1;i<=tot;++i) to[i]=Next[i]=0;
// tot=0;
// }
return 0;
}
/*
5
1 2
2 4
4 3
1 3
1 4
6
1 2
1 3
1 5
1 6
2 4
3 4
*/
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Wrong Answer
time: 1ms
memory: 5748kb
input:
6 1 2 1 3 1 4 1 5 1 6 2 3
output:
0
result:
wrong answer 1st numbers differ - expected: '10', found: '0'