QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#717399 | #6438. Crystalfly | Chihiro# | WA | 1ms | 8540kb | C++17 | 1.2kb | 2024-11-06 17:50:31 | 2024-11-06 17:50:31 |
Judging History
answer
#include<bits/stdc++.h>
#define IOS ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define endl '\n'
#define fixed(s) fixed<<setprecision(12)<<s
//#define int long long
using namespace std;
typedef pair<int, int> PII;
typedef long long ll;
typedef pair<ll, PII> PLII;
const int N = 100010;
int n;
ll dp[N][2];
ll a[N], tim[N];
vector<int> g[N];
void dfs(int u, int fa)
{
for(auto j : g[u])
{
if(j == fa)continue;
dfs(j, u);
}
dp[u][0] = 0, dp[u][1] = a[u];
ll sum = 0;
bool have3 = false;
ll max1 = 0, max2 = 0;
for(auto j : g[u])
{
if(j == fa)continue;
sum += dp[j][0];
if(tim[j] == 3)have3 = true;
if(a[j] > max1)max2 = max1, max1 = a[j];
else if(a[j] > max2)max2 = a[j];
}
sum += max1;
if(have3)sum += max2;
dp[u][0] += sum;
dp[u][1] += sum;
}
void solve()
{
cin >> n;
for(int i = 1; i <= n; i ++)
{
cin >> a[i];
g[i].clear();
}
for(int i = 1; i <= n; i ++)cin >> tim[i];
for(int i = 1; i < n; i ++)
{
int u, v;
cin >> u >> v;
g[u].push_back(v);
g[v].push_back(u);
}
dfs(1, -1);
cout << dp[1][1] << endl;
}
int main()
{
IOS
int _;
cin >> _;
while(_ --)
{
solve();
}
return 0;
}
详细
Test #1:
score: 100
Accepted
time: 1ms
memory: 8540kb
input:
2 5 1 10 100 1000 10000 1 2 1 1 1 1 2 1 3 2 4 2 5 5 1 10 100 1000 10000 1 3 1 1 1 1 2 1 3 2 4 2 5
output:
10101 10111
result:
ok 2 number(s): "10101 10111"
Test #2:
score: -100
Wrong Answer
time: 1ms
memory: 8308kb
input:
10 6 8 1 1 5 8 9 2 1 2 2 2 2 1 2 2 3 2 4 1 5 2 6 6 6 4 4 1 3 6 2 1 3 3 3 3 1 2 1 3 3 4 4 5 5 6 6 10 5 1 8 5 1 1 3 1 2 2 2 1 2 2 3 2 4 2 5 3 6 10 6 8 8 9 6 9 5 6 6 4 2 1 3 3 2 2 2 2 3 1 1 2 1 3 3 4 4 5 5 6 4 7 2 8 7 9 9 10 7 10 9 1 5 7 5 4 1 1 1 2 1 3 2 1 2 1 3 3 4 3 5 5 6 1 7 5 7 1 1 4 2 3 1 3 2 2 1...
output:
25 24 24 62 31 15 16 28 19 19
result:
wrong answer 4th numbers differ - expected: '56', found: '62'