同上模拟,注意掉落的树不可重复统计
#include <iostream>
using namespace std;
const int N = 1010;
int n,m;
int a[N];
bool st[N];
int main()
{
int d = 0;
cin >> n;
for(int i=1;i<=n;i++)
{
cin >> m;
int flag = 1;
for(int j=1;j<=m;j++)
{
int x;
cin >> x;
if(j == 1) a[i] = x;
else if(x > 0)
{
if(a[i] != x){
a[i] = x, st[i] = true;
if(flag) d ++ ,flag = 0;
}
}
else a[i] += x;
}
}
int cnt = 0;
for(int i=1;i<=n;i++) cnt += a[i];
cout<<cnt<<" "<<d<<" ";
int drop = 0;
for(int i=1;i<=n;i++)
{
if(i == 1) {
if(st[i] && st[i+1] && st[n]) drop ++;
}
else if(i == n) {
if(st[i - 1] && st[i] && st[1]) drop ++;
}
else
{
if(st[i-1] && st[i] && st[i + 1]) drop ++;
}
}
cout<<drop<<endl;
return 0;
}