제출 #1250737

#제출 시각아이디문제언어결과실행 시간메모리
1250737CrabCNHCat Exercise (JOI23_ho_t4)C++20
31 / 100
170 ms14404 KiB
#include <bits/stdc++.h> #define task "BriantheCrab" #define int long long #define pii pair <int, int> #define fi first #define se second #define szf sizeof #define sz(s) (int)((s).size()) #define all(v) (v).begin(), (v).end() typedef long long ll; typedef unsigned long long ull; typedef long double ld; using namespace std; template <class T> void minimize (T &t, T f) {if (t > f) t = f;} template <class T> void maximize (T &t, T f) {if (t < f) t = f;} const int maxN = 2e5 + 5; const int inf = 1e18 + 7; const int mod = 1e9 + 7; // khong tu code thi khong kha len duoc dau int n; int p[maxN]; vector <int> adj[maxN]; namespace sub4 { const int maxN = 5e3 + 5; int dp[maxN]; int mark[maxN]; struct cc { int node, val, dis; }; cc find (int u, int par, int d) { cc best = {u, p[u], d}; for (auto v : adj[u]) { if (v == par || mark[v]) { continue; } cc nxt = find (v, u, d + 1); if (nxt.val > best.val) { best = nxt; } } //cout << best.node << '\n'; return best; } void dfs (int u, int par) { mark[u] = 1; for (auto v : adj[u]) { if (v == par || mark[v]) { continue; } cc nxt = find (v, u, 1); dfs (nxt.node, nxt.node); //cout << nxt.node << ' ' << nxt.dis << '\n'; maximize (dp[u], dp[nxt.node] + nxt.dis); } } void sol () { for (int i = 1; i <= n; i ++) { if (p[i] == n) { dfs (i, i); cout << dp[i]; return; } } } } void solve () { cin >> n; for (int i = 1; i <= n; i ++) { cin >> p[i]; } for (int i = 1; i <= n - 1; i ++) { int u, v; cin >> u >> v; adj[u].push_back (v); adj[v].push_back (u); } if (n <= 5e3) { sub4 :: sol (); } return; } signed main () { cin.tie (nullptr) -> sync_with_stdio (false); if (fopen (task".inp", "r")) { freopen (task".inp", "r", stdin); freopen (task".out", "w", stdout); } int t = 1; //cin >> t; while (t --) { solve (); } return 0; } // thfv

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

Main.cpp: In function 'int main()':
Main.cpp:102:17: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
  102 |         freopen (task".inp", "r", stdin);
      |         ~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
Main.cpp:103:17: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
  103 |         freopen (task".out", "w", stdout);
      |         ~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
#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...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...