QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#234827 | #6654. 大纲 | stcmuyi# | WA | 29ms | 7548kb | C++20 | 1.8kb | 2023-11-01 23:17:51 | 2023-11-01 23:17:52 |
Judging History
answer
#include <bits/stdc++.h>
#define IOS ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define i64 long long
#define endl '\n'
#define lb(x) ((x) & (-x))
using namespace std;
const i64 mod = 1e9+7;
const int maxn = 1e4+10;
signed main()
{
IOS;
int t; cin >> t;
while(t--)
{
int n; cin >> n;
vector<int> l(n+1),r(n+1);
for(int i = 1; i <= n; ++i)
{
cin >> l[i];
r[i] = l[i];
if(l[i] == -1) l[i] = 0,r[i] = mod;
}
vector<vector<int>> v(n+1);
for(int i = 1; i < n; ++i)
{
int x,y; cin >> x >> y;
v[x].push_back(y);
v[y].push_back(x);
}
bool ok = 1;
auto dfs = [&](auto self,int x,int f) -> void
{
bool vis = 0;
for(int &u : v[x])
{
if(u == f) continue;
vis = 1;
self(self,u,x);
}
if(!vis) return;
int lmx = 0,lcnt = 0,rmx = 0,rcnt = 0;
for(int &u : v[x])
{
if(u == f) continue;
if(l[u] > lmx) lmx = l[u],lcnt = 1;
else if(l[u] == lmx) lcnt++;
if(r[u] > rmx) rmx = r[u],rcnt = 1;
else if(r[u] == rmx) rcnt++;
}
if(r[x] < lmx) ok = 0;
if(r[x] == lmx && lcnt > 1) ok = 0;
if(l[x] > rmx + 1) ok = 0;
if(l[x] == rmx + 1 && rcnt <= 1) ok = 0;
if(l[x] <= lmx)
{
if(lcnt <= 1) l[x] = lmx;
else l[x] = lmx+1;
}
};
dfs(dfs,1,0);
cout << (ok ? "Reasonable" : "Unreasonable") << endl;
}
return 0;
}
/*
2
3
0 -1 0
1 2
2 3
3
0 -1 0
1 2
1 3
*/
详细
Test #1:
score: 0
Wrong Answer
time: 29ms
memory: 7548kb
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:
Unreasonable Unreasonable
result:
wrong answer 1st lines differ - expected: 'Reasonable', found: 'Unreasonable'