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

#TimeUsernameProblemLanguageResultExecution timeMemory
1122145vjudge1Rigged Roads (NOI19_riggedroads)C++17
Compilation error
0 ms0 KiB
#include <bits/stdc++.h> using namespace std; #ifdef LOCAL #include "debug.h" #else #define debug(...) 42 #endif #define file(name) if (fopen(name".inp", "r")) { freopen(name".inp", "r", stdin); freopen(name".out", "w", stdout); } const int N = 3e5 + 5; int n, m; int head[N], pr[N], pos[N], tin[N], sz[N], index[N], res[N], s[4 * N]; bool inside[N], vis[N]; pair<int, int> dat[N]; vector<pair<int, int>> g[N]; void dfs(int u) { sz[u] = 1; for (auto x : g[u]) { int v, id; tie(v, id) = x; g[v].erase(find(g[v].begin(), g[v].end(), make_pair(u, id))); pr[v] = u; index[v] = id; dfs(v); sz[u] += sz[v]; } } int order; void hld(int u, int h) { head[u] = h; pos[tin[u] = ++order] = u; if (sz[u] > 1) { auto x = (*max_element(g[u].begin(), g[u].end(), [&](auto x, auto y) { return sz[x.first] < sz[y.first]; })).first; hld(x, h); for (auto v : g[u]) { if (v.first ^ x) { hld(v.first, v.first); } } } } void bld(int id = 1, int l = 1, int r = n) { if (l == r) { s[id] = index[pos[l]]; return; } int m = (l + r) / 2; bld(id * 2, l, m); bld(id * 2 + 1, m + 1, r); s[id] = min(s[id * 2], s[id * 2 + 1]); } void upd(int i, int id = 1, int l = 1, int r = n) { if (l == r) { s[id] = N; return; } int m = (l + r) / 2; i <= m ? upd(i, id * 2, l, m) : upd(i, id * 2 + 1, m + 1, r); s[id] = min(s[id * 2], s[id * 2 + 1]); } int qry(int u, int v, int id = 1, int l = 1, int r = n) { if (u <= l && r <= v) { return s[id]; } int m = (l + r) / 2; if (v <= m) { return qry(u, v, id * 2, l, m); } if (m < u) { return qry(u, v, id * 2 + 1, m + 1, r); } return min(qry(u, v, id * 2, l, m), qry(u, v, id * 2 + 1, m + 1, r)); } int get(int u, int v) { int res = N; for (; head[u] ^ head[v]; u = pr[head[u]]) { if (sz[head[u]] > sz[head[v]]) { swap(u, v); } res = min(res, qry(tin[head[u]], tin[u])); } if (tin[u] > tin[v]) { swap(u, v); } if (tin[u] + 1 <= tin[v]) { res = min(res, qry(tin[u] + 1, tin[v])); } return res; } int ans; void DFS(int id) { vis[id] = 1; int u, v; tie(u, v) = dat[id]; if (!inside[id]) { int nxt = N; while ((nxt = get(u, v)) ^ N) { DFS(nxt); } } else { upd(max(tin[u], tin[v])); } res[id] = ++ans; } int main() { ios::sync_with_stdio(false); cin.tie(nullptr); file("A"); cin >> n >> m; for (int i = 1; i <= m; ++i) { int u, v; cin >> u >> v; dat[i] = {u, v}; } for (int i = 1; i < n; ++i) { int j; cin >> j; inside[j] = 1; int u, v; tie(u, v) = dat[j]; g[u].push_back({v, j}); g[v].push_back({u, j}); } index[1] = N; dfs(1); hld(1, 1); bld(); for (int i = 1; i <= m; ++i) { if (!vis[i]) { DFS(i); } cout << res[i] << " "; } return 0; }

Compilation message (stderr)

riggedroads.cpp:16:51: error: 'int index [300005]' redeclared as different kind of entity
   16 | int head[N], pr[N], pos[N], tin[N], sz[N], index[N], res[N], s[4 * N];
      |                                                   ^
In file included from /usr/include/string.h:432,
                 from /usr/include/c++/10/cstring:42,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:48,
                 from riggedroads.cpp:1:
/usr/include/strings.h:61:1: note: previous declaration 'const char* index(const char*, int)'
   61 | index (const char *__s, int __c) __THROW
      | ^~~~~
riggedroads.cpp: In function 'void dfs(int)':
riggedroads.cpp:28:10: error: invalid types '<unresolved overloaded function type>[int]' for array subscript
   28 |     index[v] = id;
      |          ^
riggedroads.cpp: In function 'void bld(int, int, int)':
riggedroads.cpp:54:18: error: invalid types '<unresolved overloaded function type>[int]' for array subscript
   54 |     s[id] = index[pos[l]];
      |                  ^
riggedroads.cpp: In function 'int main()':
riggedroads.cpp:137:8: error: invalid types '<unresolved overloaded function type>[int]' for array subscript
  137 |   index[1] = N;
      |        ^
riggedroads.cpp:11:57: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   11 | #define file(name) if (fopen(name".inp", "r")) { freopen(name".inp", "r", stdin); freopen(name".out", "w", stdout); }
      |                                                  ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
riggedroads.cpp:123:3: note: in expansion of macro 'file'
  123 |   file("A");
      |   ^~~~
riggedroads.cpp:11:90: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   11 | #define file(name) if (fopen(name".inp", "r")) { freopen(name".inp", "r", stdin); freopen(name".out", "w", stdout); }
      |                                                                                   ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
riggedroads.cpp:123:3: note: in expansion of macro 'file'
  123 |   file("A");
      |   ^~~~