Submission #675197

#TimeUsernameProblemLanguageResultExecution timeMemory
675197vjudge1Uzastopni (COCI15_uzastopni)C++17
160 / 160
99 ms17864 KiB
#include <iostream> #include <bitset> #include <vector> #include <algorithm> #include <cstdio> using namespace std; bitset <101> dp[10001][101]; int n,a[10001],u,v,res; vector <int> ke[10001]; void dfs(int u){ dp[u][a[u]][a[u]]=1; if (ke[u].empty()) return; int pos=-1,pos2=1e9; for (int i=0;i<ke[u].size();i++){ int v=ke[u][i]; dfs(v); if (a[v]<=a[u]) pos=max(pos,i); if (a[v]>=a[u]) pos2=min(pos2,i); } for (int it=pos2;it<ke[u].size();it++){ int v=ke[u][it]; for (int j=a[u];j<=100;j++) if (!dp[u][a[u]][j]) for (int i=a[u]+1;i<=j;i++) dp[u][a[u]][j]=dp[u][a[u]][j]|(dp[u][a[u]][i-1]&dp[v][i][j]); } for (int it=pos;it>=0;it--){ int v=ke[u][it]; for (int j=1;j<=a[u];j++) if (!dp[u][j][a[u]]) for (int i=j;i<a[u];i++) dp[u][j][a[u]]=dp[u][j][a[u]]|(dp[u][i+1][a[u]]&dp[v][j][i]); } for (int i=1;i<=a[u];i++) for (int j=a[u];j<=100;j++) dp[u][i][j]=dp[u][i][j]|(dp[u][i][a[u]]&dp[u][a[u]][j]); } int main(){ ios_base::sync_with_stdio(NULL);cin.tie(nullptr); cin >> n; for (int i=1;i<=n;i++) cin >> a[i]; for (int i=1;i<n;i++){ cin >> u >> v; ke[u].push_back(v); } for (int i=1;i<=n;i++) if (!ke[i].empty()) sort(ke[i].begin(),ke[i].end(),[](int i, int j){ return a[i]<a[j]; }); dfs(1); int cnt=0; for (int i=1;i<=100;i++) for (int j=1;j<=100;j++) cnt+=dp[1][i][j]; cout << cnt; }

Compilation message (stderr)

uzastopni.cpp: In function 'void dfs(int)':
uzastopni.cpp:15:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   15 |     for (int i=0;i<ke[u].size();i++){
      |                  ~^~~~~~~~~~~~~
uzastopni.cpp:23:24: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   23 |     for (int it=pos2;it<ke[u].size();it++){
      |                      ~~^~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...