제출 #888607

#제출 시각아이디문제언어결과실행 시간메모리
888607fanwenNestabilnost (COI23_nestabilnost)C++17
41 / 100
194 ms206648 KiB
#include <bits/stdc++.h> #define fi first #define se second #define file(name) if (fopen(name".inp", "r")) { freopen(name".inp", "r", stdin); freopen(name".out", "w", stdout); } using namespace std; const int MAX = 3e5 + 5; int n, a[MAX], f[MAX]; vector <int> adj[MAX]; namespace sub1 { bool check() { return n <= 5000; } long long dp[5005][5005], ans[MAX]; void dfs(int u, int p) { for (int i = a[u] + 1; i <= n; ++i) dp[u][i] = f[i]; for (auto v : adj[u]) if(v != p) { dfs(v, u); for (int k = a[u] + 1; k <= n; ++k) { if(a[v] == (a[u] + 1) % k) { dp[u][k] += min(ans[v], dp[v][k] - f[k]); } else { dp[u][k] += ans[v]; } } } ans[u] = *min_element(dp[u] + 1, dp[u] + n + 1); } void solve() { memset(dp, 0x3f, sizeof dp); dfs(1, 0); cout << ans[1]; exit(0); } } void you_make_it(void) { cin >> n; for (int i = 1; i <= n; ++i) cin >> a[i]; for (int i = 1; i <= n; ++i) cin >> f[i]; for (int i = 1; i < n; ++i) { int u, v; cin >> u >> v; adj[u].push_back(v); adj[v].push_back(u); } if(sub1::check()) sub1::solve(); } signed main() { #ifdef LOCAL freopen("TASK.inp", "r", stdin); freopen("TASK.out", "w", stdout); #endif file("nestabilnost"); auto start_time = chrono::steady_clock::now(); cin.tie(0), cout.tie(0) -> sync_with_stdio(0); you_make_it(); auto end_time = chrono::steady_clock::now(); cerr << "\nExecution time : " << chrono::duration_cast <chrono::milliseconds> (end_time - start_time).count() << "[ms]" << endl; return (0 ^ 0); } // Dream it. Wish it. Do it.

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

code1.cpp: In function 'int main()':
code1.cpp:5:57: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
    5 | #define file(name) if (fopen(name".inp", "r")) { freopen(name".inp", "r", stdin); freopen(name".out", "w", stdout); }
      |                                                  ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
code1.cpp:61:5: note: in expansion of macro 'file'
   61 |     file("nestabilnost");
      |     ^~~~
code1.cpp:5:90: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
    5 | #define file(name) if (fopen(name".inp", "r")) { freopen(name".inp", "r", stdin); freopen(name".out", "w", stdout); }
      |                                                                                   ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
code1.cpp:61:5: note: in expansion of macro 'file'
   61 |     file("nestabilnost");
      |     ^~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...