(UPD: 2024-12-04 14:48 UTC) Judge is not working due to Cloudflare incident. (URL) We can do nothing about it, sorry. After the incident is resolved, we will grade all submissions.

Submission #1105184

#TimeUsernameProblemLanguageResultExecution timeMemory
1105184tradzDynamic Diameter (CEOI19_diameter)C++14
0 / 100
38 ms32180 KiB
#include <bits/stdc++.h> #define TIME (1.0 * clock() / CLOCKS_PER_SEC) #define For(i,a,b) for(int i = a; i <= b; i++) #define Ford(i,a,b) for(int i = a; i >= b; i--) #define ll long long #define ii pair<int,int> #define fi first #define se second #define all(v) v.begin(),v.end() #define RRH(v) v.resize(unique(all(v)) - v.begin()) using namespace std; const int N = 1e6+7; const int M = 1e9+7; const ll oo = 3e18; mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count()); long long GetRandom(long long l, long long r) { return uniform_int_distribution<long long> (l, r)(rng); } int n, q; ll w; pair <int, int> e[N]; vector<pair<int, ll>> g[N]; namespace sub1 { ll last = 0, c, len[N]; int d; void dfs(int u, int pre, int su, int sv) { for (int i = 0; i < g[u].size(); i++) { int v; ll w; tie(v, w) = g[u][i]; if (v == pre) continue; if ((u == su) && (v == sv)) { g[u][i].se = c; } else if ((u == sv) && (v == su)) { g[u][i].se = c; } w = g[u][i].se; len[v] = len[u] + w; dfs(v, u, su, sv); } } void solve() { for (int i = 1; i <= n; i++) len[i] = 0; len[0] = 0; while (q--) { cin >> d >> c; d = (1ll * d + last) % (n - 1); c = (c + last) % w; dfs(1, 0, e[d].fi, e[d].se); int mx = 0; for (int i = 1; i <= n; i++) { if (len[mx] < len[i]) { mx = i; } } len[mx] = 0; dfs(mx, 0, e[d].fi, e[d].se); mx = 0; for (int i = 1; i <= n; i++) { if (len[mx] < len[i]) { mx = i; } } if (q > 0) cout << len[mx] << '\n'; else cout << len[mx]; last = len[mx]; } } } int main() { ios::sync_with_stdio(0); cin.tie(0); #define TASK "" if (fopen (".inp", "r")) { freopen (".inp", "r", stdin); freopen (".out", "w", stdout); } if(fopen(TASK".inp", "r")) { freopen(TASK".inp", "r", stdin); freopen(TASK".out", "w", stdout); } cin >> n >> q >> w; For (i, 0, n - 2) { int u, v; ll c; cin >> u >> v >> c; e[i] = {u, v}; g[u].push_back({v, c}); g[v].push_back({u, c}); } if (max(n, q) <= 5000) { sub1 :: solve(); return 0; } cerr << "Time elapsed: " << TIME << " s.\n"; return 0; }

Compilation message (stderr)

diameter.cpp: In function 'void sub1::dfs(int, int, int, int)':
diameter.cpp:32:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   32 |         for (int i = 0; i < g[u].size(); i++) {
      |                         ~~^~~~~~~~~~~~~
diameter.cpp: In function 'int main()':
diameter.cpp:82:17: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   82 |         freopen (".inp", "r", stdin);
      |         ~~~~~~~~^~~~~~~~~~~~~~~~~~~~
diameter.cpp:83:17: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   83 |         freopen (".out", "w", stdout);
      |         ~~~~~~~~^~~~~~~~~~~~~~~~~~~~~
diameter.cpp:86:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   86 |         freopen(TASK".inp", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
diameter.cpp:87:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   87 |         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...