제출 #670731

#제출 시각아이디문제언어결과실행 시간메모리
670731nononoUzastopni (COCI15_uzastopni)C++17
160 / 160
86 ms32384 KiB
#include "bits/stdc++.h" #define SZ(x) (int)(x.size()) using namespace std; typedef bitset<100> B ; const int mxN = 1e4 + 2, mxM = 1e2; int n, v[mxN]; B dp[mxN][mxM]; vector<vector<int>> adj(mxN); void dfs(int u, int pre){ B b[mxM]; for(int v : adj[u]){ if(v == pre) continue ; dfs(v, u); for(int i = 0; i < mxM; i ++) b[i] |= dp[v][i]; } for(int i = mxM - 1; i >= 0; i --){ for(int j = i + 1; j < mxM; j ++){ if(b[i][j - 1]) b[i] |= b[j]; } } for(int i = 0; i <= v[u]; i ++){ for(int j = v[u]; j < mxM; j ++) if(((v[u] - 1 >= 0 && b[i][v[u] - 1]) || (i == v[u])) && ((v[u] + 1 < mxM && b[v[u] + 1][j]) || (j == v[u]))) dp[u][i][j] = 1; } } signed main(){ #define file "uzastopni" if(fopen(file".inp", "r")){ freopen(file".inp", "r", stdin); freopen(file".out", "w", stdout); } ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); cin >> n; for(int i = 0; i < n; i ++){ int x; cin >> x; v[i] = x - 1; } for(int i = 1; i < n; i ++){ int u, v; cin >> u >> v; u = u - 1; v = v - 1; adj[u].push_back(v); adj[v].push_back(u); } dfs(0, -1); int result = 0; for(int i = 0; i < mxM; i ++){ result += dp[0][i].count(); } cout << result ; return 0; }

컴파일 시 표준 에러 (stderr) 메시지

uzastopni.cpp: In function 'int main()':
uzastopni.cpp:39:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   39 |         freopen(file".inp", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
uzastopni.cpp:40:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   40 |         freopen(file".out", "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...