QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#563427 | #8518. Roars III | qwqwf# | WA | 4ms | 21172kb | C++14 | 1.1kb | 2024-09-14 11:44:38 | 2024-09-14 11:44:38 |
Judging History
answer
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2")
//#pragma GCC optimize("Ofast","unroll-loops","inline")
#include<bits/stdc++.h>
#define ll long long
#define int ll
#define pb push_back
#define pii pair<int,int>
#define MP make_pair
#define fi first
#define se second
using namespace std;
const int N=5e5+10,M=1e6+10,mod=998244353;
const int Inf=1e9;
int n,a[N],f[N],g[N];
char s[N];
vector<int> e[N];
void dfs(int u,int F){
f[u]=g[u]=0;
for(int v:e[u]) if(v!=F) dfs(v,u);
if(a[u]){
for(int v:e[u]) if(v!=F) g[u]=max(g[u],g[v]),f[u]+=f[v];
g[u]++;
}
else{
pii x=MP(-Inf,-Inf);
for(int v:e[u]) if(v!=F){
if(g[v]>x.fi) x.se=x.fi,x.fi=g[v];
else if(g[v]>x.se) x.se=g[v];
f[u]+=f[v];
}
g[u]=max(x.fi,x.se+1);
f[u]+=x.fi;
}
}
signed main(){
ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
cin>>n>>(s+1);
for(int i=1;i<=n;i++) a[i]=s[i]-'0';
for(int i=1,u,v;i<n;i++){
cin>>u>>v;
e[u].pb(v),e[v].pb(u);
}
for(int i=1;i<=n;i++){
dfs(i,0);
cout<<f[i]<<' ';
}
return 0;
}
詳細信息
Test #1:
score: 100
Accepted
time: 4ms
memory: 21172kb
input:
5 10101 1 2 2 3 2 4 4 5
output:
2 2 2 3 3
result:
ok 5 number(s): "2 2 2 3 3"
Test #2:
score: -100
Wrong Answer
time: 0ms
memory: 20168kb
input:
1 0
output:
-1000000000
result:
wrong answer 1st numbers differ - expected: '0', found: '-1000000000'