QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#674302#9110. Zayin and Treeucup-team5071#WA 208ms12496kbC++201.1kb2024-10-25 15:06:372024-10-25 15:06:41

Judging History

你现在查看的是最新测评结果

  • [2024-10-25 15:06:41]
  • 评测
  • 测评结果:WA
  • 用时:208ms
  • 内存:12496kb
  • [2024-10-25 15:06:37]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
int solve()
{
    int n;cin>>n;
    vector<int> a(n+1);
    int ans=1e9;
    for(int i=1;i<=n;i++)cin>>a[i],ans=min(ans,a[i]);
    vector<vector<int>> ve(n+1);
    for(int i=1;i<n;i++){
        int x,y;cin>>x>>y;
        ve[x].push_back(y);
        ve[y].push_back(x);
    }
    vector<int> mx(n+1,1e9),mi(n+1,1e9);
    auto gmin = [&](int &x,int y){
        if(y<x)x=y;
    };
    function<void(int,int)>dfs = [&](int x,int h){
        int mxx=1e9,mii=1e9;
        for(auto it:ve[x])if(it!=h){
            dfs(it,x);
            gmin(mx[x],mx[it]+1);
            gmin(mi[x],mi[it]+1);
            gmin(ans,mx[x]+mii);
            gmin(ans,mi[x]+mxx);
            gmin(mii,mi[it]);
            gmin(mxx,mx[it]);
        }
        gmin(ans,mx[x]+a[x]);
        gmin(ans,mi[x]-a[x]);
        gmin(mx[x],1-a[x]);
        gmin(mi[x],1+a[x]);
    };
    dfs(1,0);
    return ans;
}
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    int T;cin>>T;while(T--)cout<<solve()<<"\n";
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Wrong Answer
time: 208ms
memory: 12496kb

input:

3009
5
4 5 3 4 2
1 2
2 3
3 4
3 5
5
4 4 1 1 2
1 2
2 3
3 4
3 5
10
5 8 1 0 8 7 5 2 0 4
2 4
3 8
3 9
1 2
1 3
3 6
4 5
5 7
6 10
10
6 8 8 4 8 0 6 6 0 2
7 10
1 7
2 9
2 3
3 4
1 5
1 6
6 8
1 2
10
9 0 4 0 4 6 0 2 0 0
1 5
1 3
1 7
2 6
1 2
1 9
1 4
5 8
7 10
10
8 8 1 2 7 4 8 6 0 8
1 6
1 7
1 5
7 9
1 3
1 2
2 10
3 4
1 8...

output:

0
-1
-6
-6
-7
-6
-7
-4
-3
-7
-5
-6
-5
-4
-6
-3
-4
-7
-4
-4
-6
-6
-6
-5
-4
-5
-6
-6
-7
-7
-5
-7
-6
-6
-7
-6
-5
-5
-4
-6
-6
-5
-6
-6
-6
-6
-3
-6
-3
-6
-4
-6
-7
-6
-7
-6
-6
-5
-7
-6
-4
-7
-3
-5
-5
-6
-4
-5
-7
-6
-5
-5
-4
-3
-5
-3
-4
-2
-6
-5
-7
-4
-5
-5
-7
-7
-4
-6
-5
-4
-6
-5
-5
-6
-3
-6
-7
-7
-7
-6
-...

result:

wrong answer 3001st lines differ - expected: '1', found: '0'