Submission #618853

#TimeUsernameProblemLanguageResultExecution timeMemory
618853ZaniteDynamic Diameter (CEOI19_diameter)C++17
24 / 100
5075 ms20764 KiB
#include <bits/stdc++.h> using namespace std; using ll = long long; using pll = pair<ll, ll>; using Edge = pair<ll, pll>; #define fi first #define se second const int maxN = 1e5 + 5; ll n, q, w; set<pll> adj[maxN]; vector<Edge> edges; vector<ll> dist; void dfs(ll cur, ll par, ll cdist) { dist[cur] = cdist; for (auto &[nxt, w] : adj[cur]) { if (nxt == par) continue; dfs(nxt, cur, cdist+w); } } ll solve() { dist.assign(n+1, 0); dfs(1, 0, 0); ll e1 = -1, mx = -1; for (ll i = 1; i <= n; i++) { if (dist[i] > mx) { mx = dist[i]; e1 = i; } } dist.assign(n+1, 0); dfs(e1, 0, 0); ll ret = 0; for (ll i = 1; i <= n; i++) { ret = max(ret, dist[i]); } return ret; } int main() { scanf("%lld %lld %lld", &n, &q, &w); for (ll a, b, c, i = 1; i < n; i++) { scanf("%lld %lld %lld", &a, &b, &c); adj[a].insert({b, c}); adj[b].insert({a, c}); edges.push_back({c, {a, b}}); } ll last = 0; for (ll d, e, i = 1; i <= q; i++) { scanf("%lld %lld", &d, &e); d = (d + last) % (n - 1); e = (e + last) % w; auto &[w, p] = edges[d]; adj[p.fi].erase({p.se, w}); adj[p.se].erase({p.fi, w}); edges[d].fi = e; adj[p.fi].insert({p.se, e}); adj[p.se].insert({p.fi, e}); /* for (ll i = 1; i <= n; i++) { cout << i << ": "; for (auto &[j, k] : adj[i]) { cout << "{" << j << ", " << k << "} "; } cout << '\n'; } */ last = solve(); printf("%lld\n", last); } }

Compilation message (stderr)

diameter.cpp: In function 'int main()':
diameter.cpp:50:7: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   50 |  scanf("%lld %lld %lld", &n, &q, &w);
      |  ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
diameter.cpp:52:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   52 |   scanf("%lld %lld %lld", &a, &b, &c);
      |   ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
diameter.cpp:59:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   59 |   scanf("%lld %lld", &d, &e);
      |   ~~~~~^~~~~~~~~~~~~~~~~~~~~
#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...