QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#698557 | #8333. Gift | sdmrlh# | WA | 2ms | 9816kb | C++14 | 1.2kb | 2024-11-01 20:28:11 | 2024-11-01 20:28:12 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
#define sf(x) scanf("%lld",&x)
#define sff(x,y) scanf("%lld%lld",&x,&y)
#define endl '\n'
#define IOS ios::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define pf(x) printf("%lld",x)
#define pii pair<int,int>
#define f first
#define s second
#define int long long
//
const int N = 1e6+10;
int h[N],e[N],ne[N],idx;
int dd,st[N];
int res,ru[N],sum;
bool dfs(int u,int fa)
{
st[u]=1;
for(int i=h[u];~i;i=ne[i])
{
int j=e[i];
if(j==fa) continue;
if(st[j])
{
if(ru[j]-1==3) sum++;
if(ru[u]-1==3) sum++;
sum+=res;
dd=j;
return 0;
}
if(!dfs(j,u))
{
if(dd==u){
cout<<sum<<endl;
exit(0);
}
int now=0;
if(ru[j]-1==3) sum++;
if(ru[u]-1==3) sum++;
sum+=res;
return 0;
}
}
return 1;
}
void add(int a,int b)
{
ne[idx]=h[a],e[idx]=b,h[a]=idx++;
}
//
//
void solve()
{
int m;
cin>>m;
res=m;
for(int i=1;i<=m;i++) h[i]=-1;
for(int i=1;i<=m;i++)
{
int a,b;
cin>>a>>b;
add(a,b);
add(b,a);
ru[a]++;
ru[b]++;
}
for(int i=1;i<=m;i++)
if(ru[i]>=4) res--;
dfs(1,-1);
}
signed main()
{
IOS;
int _=1;
while(_--)
solve();
return 0;
}
详细
Test #1:
score: 100
Accepted
time: 2ms
memory: 9816kb
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: 2ms
memory: 9756kb
input:
3 1 3 3 2 2 1
output:
6
result:
wrong answer 1st numbers differ - expected: '9', found: '6'