#include <bits/stdc++.h>
using namespace std ;
#define int int64_t //be careful about this
#define endl "\n"
#define f(i,a,b) for(int i=int(a);i<int(b);++i)
#define pr pair
#define ar array
#define fr first
#define sc second
#define vt vector
#define pb push_back
#define eb emplace_back
#define LB lower_bound
#define UB upper_bound
#define PQ priority_queue
#define sz(x) ((int)(x).size())
#define all(a) (a).begin(),(a).end()
#define allr(a) (a).rbegin(),(a).rend()
#define mem0(a) memset(a, 0, sizeof(a))
#define mem1(a) memset(a, -1, sizeof(a))
template<class A> void rd(vt<A>& v);
template<class T> void rd(T& x){ cin >> x; }
template<class H, class... T> void rd(H& h, T&... t) { rd(h) ; rd(t...) ;}
template<class A> void rd(vt<A>& x) { for(auto& a : x) rd(a) ;}
template<class T> bool ckmin(T& a, const T& b) { return b < a ? a = b, 1 : 0; }
template<class T> bool ckmax(T& a, const T& b) { return a < b ? a = b, 1 : 0; }
template<typename T>
void __p(T a) {
cout<<a;
}
template<typename T, typename F>
void __p(pair<T, F> a) {
cout<<"{";
__p(a.first);
cout<<",";
__p(a.second);
cout<<"}\n";
}
template<typename T>
void __p(std::vector<T> a) {
cout<<"{";
for(auto it=a.begin(); it<a.end(); it++)
__p(*it),cout<<",}\n"[it+1==a.end()];
}
template<typename T, typename ...Arg>
void __p(T a1, Arg ...a) {
__p(a1);
__p(a...);
}
template<typename Arg1>
void __f(const char *name, Arg1 &&arg1) {
cout<<name<<" : ";
__p(arg1);
cout<<endl;
}
template<typename Arg1, typename ... Args>
void __f(const char *names, Arg1 &&arg1, Args &&... args) {
int bracket=0,i=0;
for(;; i++)
if(names[i]==','&&bracket==0)
break;
else if(names[i]=='(')
bracket++;
else if(names[i]==')')
bracket--;
const char *comma=names+i;
cout.write(names,comma-names)<<" : ";
__p(arg1);
cout<<" | ";
__f(comma+1,args...);
}
void setIO(string s = "") {
ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
cin.exceptions(cin.failbit);
cout.precision(15); cout << fixed;
#ifdef ONLINE_JUDGE
if(sz(s)){
freopen((s+".in").c_str(),"r",stdin);
freopen((s+".out").c_str(),"w",stdout);
}
#define __f(...) 0
#endif
}
const int MAX_V = 100, MAX_N = 10000;
bitset<MAX_V> bs[MAX_N],Z;
vt<int> mx(MAX_N), mn(MAX_N);
signed main(){
setIO();
int n; rd(n);
vt<int> v(n); rd(v);
f(i,0,n) --v[i];
vt<int> g[n];
f(_,0,n-1){
int a,b; rd(a,b); --a,--b;
g[a].pb(b);
}
int ans = 0;
f(L,0,MAX_V) f(R,L,MAX_V) if(L <= v[0] && v[0] <= R){
//[L,..,R]
f(i,0,n){
bs[i] = Z;
bs[i][v[i]] = 1;
mx[i] = mn[i] = v[i];
}
function<bool(int)> dfs=[&](int i){
int chk = 1;
for(auto j : g[i]) {
if(L <= v[j] && v[j] <= R){
if(!dfs(j)) return false;
chk += int(bs[j].count());
ckmax(mx[i],mx[j]);
ckmin(mn[i],mn[j]);
bs[i] |= bs[j];
}
}
if(chk != bs[i].count() || chk != mx[i] - mn[i] + 1){
return false;
}
return true;
};
if(dfs(0) && mn[0] == L && mx[0] == R) ans++;
}
cout << ans << endl;
}
Compilation message
uzastopni.cpp: In lambda function:
uzastopni.cpp:125:12: warning: comparison of integer expressions of different signedness: 'int64_t' {aka 'long int'} and 'std::size_t' {aka 'long unsigned int'} [-Wsign-compare]
125 | if(chk != bs[i].count() || chk != mx[i] - mn[i] + 1){
| ~~~~^~~~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
580 KB |
Output isn't correct |
2 |
Incorrect |
1 ms |
460 KB |
Output isn't correct |
3 |
Incorrect |
1 ms |
460 KB |
Output isn't correct |
4 |
Incorrect |
1 ms |
476 KB |
Output isn't correct |
5 |
Incorrect |
2 ms |
460 KB |
Output isn't correct |
6 |
Correct |
2 ms |
460 KB |
Output is correct |
7 |
Correct |
3 ms |
476 KB |
Output is correct |
8 |
Correct |
1 ms |
460 KB |
Output is correct |
9 |
Incorrect |
1 ms |
476 KB |
Output isn't correct |
10 |
Incorrect |
1 ms |
460 KB |
Output isn't correct |
11 |
Incorrect |
55 ms |
1160 KB |
Output isn't correct |
12 |
Incorrect |
17 ms |
1228 KB |
Output isn't correct |
13 |
Incorrect |
16 ms |
1220 KB |
Output isn't correct |
14 |
Incorrect |
101 ms |
2524 KB |
Output isn't correct |
15 |
Correct |
71 ms |
2520 KB |
Output is correct |
16 |
Incorrect |
96 ms |
2560 KB |
Output isn't correct |
17 |
Incorrect |
22 ms |
1128 KB |
Output isn't correct |
18 |
Incorrect |
14 ms |
1244 KB |
Output isn't correct |
19 |
Incorrect |
131 ms |
1128 KB |
Output isn't correct |
20 |
Incorrect |
119 ms |
1120 KB |
Output isn't correct |