QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#283006#6654. 大纲one_god_and_two_dogs#WA 40ms19092kbC++141.3kb2023-12-13 17:39:462023-12-13 17:39:47

Judging History

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

  • [2023-12-13 17:39:47]
  • 评测
  • 测评结果:WA
  • 用时:40ms
  • 内存:19092kb
  • [2023-12-13 17:39:46]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
const int M=2e5+5;
int T;
int a[M];
vector<int>Q[M];
int L[M],R[M];
bool f;
void dfs(int now) {
    if(!f)return;
    if(Q[now].size()==0) {
        if(~a[now])L[now]=R[now]=a[now];
        return;
    }
    int mxl=-1,mxr=-1,cntl=0,cntr=0;
    bool Have=false;
    for(int i=0; i<Q[now].size(); ++i) {
        int To=Q[now][i];
        dfs(To);
        if(L[To]>mxl)mxl=L[To],cntl=0;
        else if(L[To]==mxl)cntl++;
        if(R[To]>mxr)mxr=R[To],cntr=0;
        else if(R[To]==mxr)cntr++;
        if(R[To]==-1)Have=true;
    }
    if(cntl>0)mxl++;
    if(cntr>0)mxr++;
    if(Have||a[now]==-1)mxr=-1;
    if(~a[now]) {
        if(mxl<=a[now]&&(a[now]<=mxr||mxr==-1))L[now]=R[now]=a[now];
        else f=false;
    }else L[now]=mxl,R[now]=mxr;
}
int main() {
    scanf("%d",&T);
    while(T--) {
        int n;
        scanf("%d",&n);
        for(int i=1; i<=n; ++i)L[i]=0,R[i]=-1,Q[i].clear();
        for(int i=1; i<=n; ++i)scanf("%d",&a[i]);
        for(int i=1; i<n; ++i) {
            int u,v;
            scanf("%d%d",&u,&v);
            Q[u].push_back(v);
        }
        f=true;
        dfs(1);
        if(f)puts("Reasonable");
        else puts("Unreasonable");
    }
    return 0;
}

详细

Test #1:

score: 100
Accepted
time: 25ms
memory: 11884kb

input:

2
65535
-1 1000000000 -1 1000000000 1000000000 1000000000 -1 -1 -1 -1 -1 -1 1000000000 1000000000 1000000000 1000000000 -1 1000000000 1000000000 -1 1000000000 -1 1000000000 1000000000 -1 -1 -1 -1 -1 -1 -1 -1 -1 1000000000 1000000000 -1 1000000000 -1 -1 -1 1000000000 1000000000 1000000000 1000000000 ...

output:

Reasonable
Unreasonable

result:

ok 2 lines

Test #2:

score: 0
Accepted
time: 19ms
memory: 11884kb

input:

2
65535
1000000000 -1 -1 -1 1000000000 -1 -1 -1 -1 -1 1000000000 1000000000 -1 1000000000 -1 -1 -1 -1 1000000000 -1 1000000000 1000000000 -1 1000000000 1000000000 -1 1000000000 -1 1000000000 -1 1000000000 1000000000 -1 -1 1000000000 -1 -1 1000000000 1000000000 1000000000 -1 -1 -1 -1 1000000000 10000...

output:

Unreasonable
Reasonable

result:

ok 2 lines

Test #3:

score: 0
Accepted
time: 40ms
memory: 19092kb

input:

2
99999
49999 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -...

output:

Reasonable
Reasonable

result:

ok 2 lines

Test #4:

score: 0
Accepted
time: 25ms
memory: 8332kb

input:

100000
2
503237730 503237730
1 2
2
940454426 940454426
1 2
2
248079005 -1
1 2
2
74614856 74614857
1 2
2
64379558 64379558
1 2
2
306909809 -1
1 2
2
-1 966615641
1 2
2
698391106 698391107
1 2
2
223750421 -1
1 2
2
705201637 705201637
1 2
2
256204065 -1
1 2
2
723177111 168932444
1 2
2
228089673 22808967...

output:

Reasonable
Reasonable
Reasonable
Unreasonable
Reasonable
Reasonable
Reasonable
Unreasonable
Reasonable
Reasonable
Reasonable
Unreasonable
Reasonable
Unreasonable
Reasonable
Reasonable
Unreasonable
Reasonable
Reasonable
Reasonable
Unreasonable
Reasonable
Reasonable
Reasonable
Reasonable
Reasonable
Un...

result:

ok 100000 lines

Test #5:

score: -100
Wrong Answer
time: 30ms
memory: 10000kb

input:

66666
3
530204916 -1 -1
2 3
1 2
3
476528072 476528072 476528072
1 2
2 3
3
-1 841888306 841888306
1 3
1 2
3
319191766 319191766 -1
3 2
1 3
3
177048577 531221023 -1
1 2
1 3
3
598759147 991100533 416954424
1 3
3 2
3
210423414 263192668 -1
1 2
1 3
3
902429034 -1 961317874
1 3
1 2
3
662280681 -1 33815376...

output:

Reasonable
Reasonable
Reasonable
Reasonable
Unreasonable
Unreasonable
Unreasonable
Unreasonable
Reasonable
Unreasonable
Unreasonable
Unreasonable
Unreasonable
Reasonable
Reasonable
Reasonable
Reasonable
Reasonable
Reasonable
Unreasonable
Unreasonable
Reasonable
Unreasonable
Unreasonable
Reasonable
R...

result:

wrong answer 9th lines differ - expected: 'Unreasonable', found: 'Reasonable'