Submission #1277289

#TimeUsernameProblemLanguageResultExecution timeMemory
1277289vuquangsangUzastopni (COCI15_uzastopni)C++20
160 / 160
96 ms18324 KiB
#include <bits/stdc++.h> using namespace std; const int N = 1e4 + 2; int n, a[N], lim; vector<int> adj[N]; bitset<105> dp[N][105], temp[105]; void dfs(int u) { for(int v : adj[u]) dfs(v); for(int x = 1; x <= lim; x++) temp[x].reset(); temp[a[u]][a[u]] = 1; for(int v : adj[u]) { for(int x = 1; x <= lim; x++) temp[x] |= dp[v][x]; } dp[u][a[u]][a[u]] = 1; for(int x = 1; x <= lim; x++) for(int y = x; y <= lim; y++) if(temp[x][y]) temp[x] |= temp[y + 1]; for(int x = 1; x <= lim; x++) for(int y = x; y <= lim; y++) { if(x == a[u] && temp[x + 1][y]) dp[u][x][y] = 1; if(y == a[u] && temp[x][y - 1]) dp[u][x][y] = 1; if(temp[x][a[u] - 1] && temp[a[u] + 1][y]) dp[u][x][y] = 1; } } void solve() { cin >> n; for(int i = 1; i <= n; i++) cin >> a[i]; for(int i = 1; i < n; i++) { int x, y; cin >> x >> y; adj[x].push_back(y); } lim = 100; dfs(1); int ans = 0; for(int x = 1; x <= lim; x++) for(int y = x; y <= lim; y++) ans += dp[1][x][y]; cout << ans; } main() { ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0); #define TASK "COCI15_uzastopni" if(fopen(TASK".INP", "r")) { freopen(TASK".INP", "r", stdin); freopen(TASK".OUT", "w", stdout); } solve(); cerr << "\nTime" << 0.001 * clock() << "s "; return 0; }

Compilation message (stderr)

uzastopni.cpp:44:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   44 | main()
      | ^~~~
uzastopni.cpp: In function 'int main()':
uzastopni.cpp:50:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   50 |         freopen(TASK".INP", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
uzastopni.cpp:51:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   51 |         freopen(TASK".OUT", "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...