제출 #693252

#제출 시각아이디문제언어결과실행 시간메모리
693252Tien_NoobUzastopni (COCI15_uzastopni)C++17
160 / 160
63 ms18448 KiB
//Make CSP great again //Vengeance #include <bits/stdc++.h> #define TASK "TESTCODE" using namespace std; const int N = 1e4, M = 1e2; int a[N + 1], n; vector<int> adj[N + 1]; bitset<M + 1> dp[N + 1][M + 1]; void read() { cin >> n; for (int i = 1; i <= n; ++ i) { cin >> a[i]; } for (int i = 1; i < n; ++ i) { int u, v; cin >> u >> v; adj[u].push_back(v); } } void DFS(int u) { dp[u][a[u]][a[u]] = true; for (int v : adj[u]) { if (a[v] > a[u]) { DFS(v); for (int i = 1; i <= M; ++ i) { vector<int> avail; for (int j = i; j < M; ++ j) { if (dp[u][i][j]) { avail.push_back(j + 1); } } for (int j : avail) { dp[u][i] |= dp[v][j]; } } } } reverse(adj[u].begin(), adj[u].end()); for (int v : adj[u]) { if (a[v] < a[u]) { DFS(v); for (int i = 1; i <= M; ++ i) { vector<int> avail; for (int j = i; j < M; ++ j) { if (dp[v][i][j]) { avail.push_back(j + 1); } } for (int j : avail) { dp[u][i] |= dp[u][j]; } } } } } void solve() { for (int u = 1; u <= n; ++ u) { sort(adj[u].begin(), adj[u].end(), [&](const int &x, const int &y) { return a[x] < a[y]; }); } DFS(1); int res = 0; for (int i = 1; i <= M; ++ i) { res += dp[1][i].count(); } cout << res; } int main() { ios_base::sync_with_stdio(false); cin.tie(nullptr); if (fopen(TASK".INP", "r")) { freopen(TASK".INP", "r", stdin); //freopen(TASK".OUT", "w", stdout); } int t = 1; bool typetest = false; if (typetest) { cin >> t; } for (int __ = 1; __ <= t; ++ __) { //cout << "Case " << __ << ": "; read(); solve(); } }

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

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