Submission #556053

#TimeUsernameProblemLanguageResultExecution timeMemory
556053Tien_NoobOne-Way Streets (CEOI17_oneway)C++17
100 / 100
132 ms29120 KiB
//Make CSP great again //Vengeance #include <bits/stdc++.h> #define TASK "TESTCODE" #define Log2(x) 31 - __builtin_clz(x) using namespace std; const int N = 1e5, cbit = 16; vector<int> adj[N + 1], edge[N + 1]; int n, m, q, l[N + 1], r[N + 1], dp[N + 1][2], f[N + 1][cbit + 1], p[N + 1], res[N + 1], depth[N + 1]; int num[N + 1], low[N + 1], Count, Comp[N + 1], CompCount; stack<int> st; bool visited[N + 1]; void read() { cin >> n >> m; for (int i = 1; i <= m; ++ i) { cin >> l[i] >> r[i]; adj[l[i]].push_back(i); adj[r[i]].push_back(i); } } void visit(int u, int pre) { st.push(u); num[u] = low[u] = ++Count; for (int i : adj[u]) { if (i == pre) { continue; } int v = l[i] ^ u ^ r[i]; if (num[v]) { low[u] = min(low[u], num[v]); } else { visit(v, i); low[u] = min(low[u], low[v]); } } if (low[u] == num[u]) { int v; ++CompCount; do { v = st.top(); st.pop(); Comp[v] = CompCount; low[v] = num[v] = 1e9; } while(v != u); } } void Compress(int u) { visited[u] = true; for (int i : adj[u]) { int v = l[i] ^ r[i] ^ u; if (Comp[u] == Comp[v]) { res[i] = 2; } if (visited[v]) { continue; } if (Comp[v] != Comp[u]) { p[Comp[v]] = i; edge[Comp[u]].push_back(Comp[v]); depth[Comp[v]] = depth[Comp[u]] + 1; f[Comp[v]][0] = Comp[u]; for (int k = 1; k <= cbit; ++ k) { f[Comp[v]][k] = f[f[Comp[v]][k - 1]][k - 1]; } //cerr << Comp[u] << ' ' << Comp[v] << '\n'; } Compress(v); } } int LCA(int u, int v) { if (depth[u] > depth[v]) { swap(u, v); } int k = depth[v] - depth[u]; for (int i = cbit; i >= 0; -- i) { if ((k >> i) & 1) { v = f[v][i]; } } if (u == v) { return u; } for (int i = cbit; i >= 0; -- i) { if (f[u][i] != f[v][i]) { u = f[u][i]; v = f[v][i]; } } return f[u][0]; } void DFS(int u) { //0 : R, 1 : L, 2 : B for (int v : edge[u]) { DFS(v); dp[u][0] += dp[v][0]; dp[u][1] += dp[v][1]; int i = p[v]; if (dp[v][0] == 0 && dp[v][1] == 0) { res[i] = 2; continue; } if (dp[v][0] > 0 && depth[Comp[l[i]]] < depth[Comp[r[i]]]) { res[i] = 1; } if (dp[v][1] > 0 && depth[Comp[l[i]]] > depth[Comp[r[i]]]) { res[i] = 1; } } } void solve() { for (int i = 1; i <= n; ++ i) { if (num[i] == 0) { visit(i, 0); } } //cerr << Comp[1] << ' ' << Comp[2] << '\n'; for (int i = 1; i <= n; ++ i) { if (!visited[i]) { Compress(i); } } cin >> q; while(q--) { int u, v; cin >> u >> v; u = Comp[u]; v = Comp[v]; if (u == v) { continue; } int l = LCA(u, v); ++dp[u][0]; --dp[l][0]; ++dp[v][1]; --dp[l][1]; //cerr << u << ' ' << l << ' ' << v << '\n'; } for (int i = 1; i <= CompCount; ++ i) { if (depth[i] == 0) { DFS(i); } } for (int i = 1; i <= m; ++ i) { if (res[i] == 2) { cout << 'B'; } if (res[i] == 1) { cout << 'L'; } if (res[i] == 0) { cout << 'R'; } } } int main() { ios_base::sync_with_stdio(false); cin.tie(nullptr); if (fopen(TASK".INP", "r")) { freopen(TASK".INP", "r", stdin); //freopen(TASK".OUT", "w", stdout); } int t = 1; bool typetest = false; if (typetest) { cin >> t; } for (int __ = 1; __ <= t; ++ __) { //cout << "Case " << __ << ": "; read(); solve(); } }

Compilation message (stderr)

oneway.cpp: In function 'int main()':
oneway.cpp:203:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
  203 |         freopen(TASK".INP", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...