QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#668714 | #8333. Gift | beidiaodajht# | WA | 1ms | 5928kb | C++23 | 1.5kb | 2024-10-23 15:38:38 | 2024-10-23 15:38:38 |
Judging History
answer
// #include<bits/stdc++.h>
// using namespace std;
// int n,b[1005];
// vector<pair<int,int> >ans;
// void solve(int l,int r){
// if(l==r) return ;
// int mid=(l+r)>>1;
// for(int i=1;i<=n;++i) if(b[i]>mid&&b[i]<=r) ans.emplace_back(make_pair(2,i));
// for(int i=l+1;i<=mid;++i) ans.emplace_back(make_pair(1,i));
// solve(l,mid);solve(mid+1,r);
// }
// int main(){
// scanf("%d",&n);
// for(int i=1;i<=n;++i) scanf("%d",&b[i]);
// solve(0,n);
// printf("%d\n",ans.size());
// for(auto a:ans) printf("%d %d\n",a.first,a.second);
// return 0;
// }
//A
#include<bits/stdc++.h>
#define M 100005
using namespace std;
int n,_4,_5,fa[M],Fa[M],dep[M],du[M],U,V;
long long ans;
vector<int> e[M];
void dfs(int u,int fa){
for(int v:e[u]) if(v!=fa){
dep[v]=dep[u]+1;Fa[v]=u;
dfs(v,u);
}
}
void del(int x){
_4-=du[x]==4;_5-=du[x]==5;
du[x]--;
_4+=du[x]==4;_5+=du[x]==5;
}
void add(int x){
_4-=du[x]==4;_5-=du[x]==5;
du[x]++;
_4+=du[x]==4;_5+=du[x]==5;
}
int find(int x){return x==fa[x]?x:fa[x]=find(fa[x]);}
int main(){
scanf("%d",&n);
for(int i=1;i<=n;++i) fa[i]=i;
for(int i=1,u,v;i<=n;++i){
scanf("%d%d",&u,&v);du[u]++;du[v]++;
if(find(u)!=find(v)) e[u].emplace_back(v),e[v].emplace_back(u),fa[find(u)]=find(v);
else U=u;V=v;
}
for(int i=1;i<=n;++i) _4+=du[i]==4,_5+=du[i]==5;
dfs(1,0);
while(U!=V){
if(dep[V]>dep[U]) swap(U,V);
del(U);del(Fa[U]);
if(!_5) ans+=n-_4;
add(U);add(Fa[U]);U=Fa[U];
}
printf("%lld",ans);
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 3884kb
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: 5928kb
input:
3 1 3 3 2 2 1
output:
6
result:
wrong answer 1st numbers differ - expected: '9', found: '6'