Submission #473973

#TimeUsernameProblemLanguageResultExecution timeMemory
473973Lam_lai_cuoc_doiSynchronization (JOI13_synchronization)C++17
0 / 100
445 ms44792 KiB
#include <bits/stdc++.h> using namespace std; using ll = long long; using ld = long double; using ull = unsigned long long; template <class T> void read(T &x) { x = 0; register int c; while ((c = getchar()) && (c > '9' || c < '0')) ; for (; c >= '0' && c <= '9'; c = getchar()) x = x * 10 + c - '0'; } constexpr bool typetest = 0; constexpr int N = 2e5 + 5; constexpr int Inf = 1e9 + 7; vector<pair<int, int>> adj[N]; vector<int> dp[N], pos[N]; int n, m, q, last[N]; int u[N], v[N]; bool ck[N]; void Read() { cin >> n >> m >> q; for (int i = 1; i < n; ++i) cin >> u[i] >> v[i]; for (int i = 1; i <= m; ++i) { int x; cin >> x; ck[x] = !ck[x]; if (ck[x]) { adj[u[x]].emplace_back(i, v[x]); adj[v[x]].emplace_back(i, u[x]); //cerr << u[x] << " " << v[x] << " " << i << "\n"; } else { adj[u[x]].emplace_back(i - 1, v[x]); adj[v[x]].emplace_back(i - 1, u[x]); //cerr << u[x] << " " << v[x] << " " << i - 1 << "\n"; } } } int f(int v, int p) { cout << v << " " << adj[v][p].first << "\n"; if (dp[v][p] != -1) return dp[v][p]; dp[v][p] = 1; for (auto i : adj[v]) last[i.second] = 0; for (int i = (int)adj[v].size() - 1; i > p; --i) if (adj[v][i].second != adj[v][p].second) { int tmp = f(adj[v][i].second, pos[v][i]); dp[v][p] += tmp - last[adj[v][i].second]; last[adj[v][i].second] = tmp; } return dp[v][p]; } int Get(vector<pair<int, int>> &s, int v) { int l = 0, m, h = s.size() - 1; while (l <= h) { m = (l + h) / 2; if (s[m].first > v) l = m + 1; else h = m - 1; } return l; } void Solve() { for (int i = 1; i <= n; ++i) { adj[i].emplace_back(m + 1, 0); dp[i].assign(adj[i].size() + 2, -1); pos[i].assign(adj[i].size() + 2, -1); sort(adj[i].rbegin(), adj[i].rend()); } for (int i = 1; i <= n; ++i) for (int j = 1; j < (int)adj[i].size(); ++j) pos[i][j] = Get(adj[adj[i][j].second], adj[i][j].first); //cerr << "ok\n"; while (q--) { int x; cin >> x; cout << f(x, 0) << "\n"; } } int32_t main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); int t(1); if (typetest) cin >> t; for (int _ = 1; _ <= t; ++_) { //cout << "Case #" << _ << ": "; Read(); Solve(); } //cerr << "\nTime elapsed: " << 1000 * clock() / CLOCKS_PER_SEC << "ms\n"; }

Compilation message (stderr)

synchronization.cpp: In function 'void read(T&)':
synchronization.cpp:12:18: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister]
   12 |     register int c;
      |                  ^
#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...