QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#720656 | #8333. Gift | AnotherDayofSun# | WA | 0ms | 6468kb | C++14 | 1.5kb | 2024-11-07 13:35:49 | 2024-11-07 13:35:49 |
Judging History
answer
#include<bits/stdc++.h>
#define For(i,j,k) for(int i=(j);i<=(k);i++)
#define re
#define vi vector<int>
#define pb push_back
#define ll long long
#define P 998244353
using namespace std;
inline int read(){
re char c;int res=0;bool flag=0;
while(c=getchar(),c<48)(c=='-')&&(flag=1);
do res=(res<<3)+(res<<1)+(c^48);
while(c=getchar(),c>47);
flag&&(res=-res);
return res;
}
const int MN=1e5+5;
int n,deg[MN],tdeg[MN],cnt,vis[MN];
vi e[MN];
signed main() {
n=read();
For(i,1,n) {
int u=read(),v=read();
e[u].pb(v),e[v].pb(u);
deg[u]++,deg[v]++;
}
For(i,1,n) {
tdeg[i]=deg[i];
if(deg[i]>=6) {
printf("0\n");
return 0;
}
}
queue<int>q;
For(i,1,n) {
if(tdeg[i]==1) q.push(i);
}
while(q.size()) {
int u=q.front(); q.pop();
vis[u]=1;
for(auto v:e[u]) {
--tdeg[v];
if(!vis[v]&&tdeg[v]==1) q.push(v);
}
}
long long ans1=0; int ans2=0,cnt5=0;
For(i,1,n) ans2+=deg[i]==4,cnt5+=deg[i]==5;
// cerr<<cnt5<<endl;
if(cnt5>=2) return printf("0\n"),0;
if(cnt5==1) {
For(i,1,n) if(deg[i]==5) {
if(vis[i]) return printf("0\n"),0;
else {
int ans=0;
for(auto j:e[i]) {
if(!vis[j]) {
if(deg[j]==4) ans+=n-1-(ans2-1);
else ans+=n-1-ans2;
}
}
printf("%d\n",ans);
return 0;
}
}
}
For(i,1,n) {
if(!vis[i]) {
for(auto j:e[i]) {
if(!vis[j]) {
int c1=(deg[i]==4)+(deg[j]==4);
ans1+=(n-(ans2-c1+2));
}
}
}
}
cout<<ans1/2<<endl;
return 0;
}
详细
Test #1:
score: 100
Accepted
time: 0ms
memory: 6348kb
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: 0ms
memory: 6468kb
input:
3 1 3 3 2 2 1
output:
3
result:
wrong answer 1st numbers differ - expected: '9', found: '3'