Submission #675186

#TimeUsernameProblemLanguageResultExecution timeMemory
675186abcvuitunggioUzastopni (COCI15_uzastopni)C++17
80 / 160
1 ms1236 KiB
#include <iostream> #include <bitset> #include <vector> #include <algorithm> using namespace std; bool dp[10001][101][101]; int n,a[101],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]][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][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][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++) sort(ke[i].begin(),ke[i].end(),[](int i, int j){ return a[i]<a[j]; }); dfs(1); int cnt=0,cnt2=0; for (int i=1;i<=100;i++) cnt+=dp[1][i][a[1]],cnt2+=dp[1][a[1]][i]; cout << cnt*cnt2; }

Compilation message (stderr)

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