Submission #405438

# Submission time Handle Problem Language Result Execution time Memory
405438 2021-05-16T11:43:02 Z codebuster_10 Uzastopni (COCI15_uzastopni) C++17
32 / 160
132 ms 2396 KB
#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 != int(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;
}

# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 460 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 460 KB Output isn't correct
5 Incorrect 1 ms 460 KB Output isn't correct
6 Correct 2 ms 460 KB Output is correct
7 Correct 3 ms 460 KB Output is correct
8 Correct 1 ms 460 KB Output is correct
9 Incorrect 1 ms 460 KB Output isn't correct
10 Incorrect 1 ms 460 KB Output isn't correct
11 Incorrect 53 ms 1100 KB Output isn't correct
12 Incorrect 16 ms 1120 KB Output isn't correct
13 Incorrect 15 ms 1120 KB Output isn't correct
14 Incorrect 103 ms 2396 KB Output isn't correct
15 Correct 69 ms 2380 KB Output is correct
16 Incorrect 96 ms 2380 KB Output isn't correct
17 Incorrect 19 ms 1116 KB Output isn't correct
18 Incorrect 12 ms 1100 KB Output isn't correct
19 Incorrect 132 ms 1012 KB Output isn't correct
20 Incorrect 117 ms 1012 KB Output isn't correct