(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 #1105189

#TimeUsernameProblemLanguageResultExecution timeMemory
1105189tradzDynamic Diameter (CEOI19_diameter)C++14
24 / 100
1313 ms32124 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) { if ((u == su) && (v == sv)) { g[u][i].se = c; } else if ((v == su) && (u == sv)) { g[u][i].se = c; } 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; } } // cout << d << " " << c << '\n'; 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:92:17: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   92 |         freopen (".inp", "r", stdin);
      |         ~~~~~~~~^~~~~~~~~~~~~~~~~~~~
diameter.cpp:93:17: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   93 |         freopen (".out", "w", stdout);
      |         ~~~~~~~~^~~~~~~~~~~~~~~~~~~~~
diameter.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);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
diameter.cpp:97:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   97 |         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...