Submission #367632

#TimeUsernameProblemLanguageResultExecution timeMemory
367632Sparky_09One-Way Streets (CEOI17_oneway)C++17
100 / 100
233 ms22508 KiB
#include "bits/stdc++.h" using namespace std; #define rep(i, a, b) for(int i = a; i < (b); ++i) #define all(x) begin(x), end(x) #define trav(a, x) for(auto& a : x) #define sz(x) (int)(x).size() typedef long long ll; typedef pair<int, int> pii; typedef vector<int> vi; typedef vector<pii> vpi; template <class T> void rd(T &x) { int sgn = 1; char ch; x = 0; for (ch = getchar(); (ch < '0' || ch > '9') && ch != '-'; ch = getchar()) ; if (ch == '-') ch = getchar(), sgn = -1; for (; '0' <= ch && ch <= '9'; ch = getchar()) x = x * 10 + ch - '0'; x *= sgn; } template <class T> void wr(T x) { if (x < 0) putchar('-'), wr(-x); else if (x < 10) putchar(x + '0'); else wr(x / 10), putchar(x % 10 + '0'); } template<class T> bool ckmin(T& a, const T& b) { return a > b ? a = b, 1 : 0; } template<class T> bool ckmax(T& a, const T& b) { return a < b ? a = b, 1 : 0; } void usaco(string s){ freopen((s+".in").c_str(), "r", stdin); freopen((s+".out").c_str(), "w", stdout); } pii node[100010]; vector<pii> edge[100010], e[100010]; int n, m, disc[100010], low[100010], tot, stck[100010], tp, color[100010], cnt, w[100010]; bool proc[100010]; char ans[100010]; void tarjan(int x, int id){ disc[x] = low[x] = ++tot; stck[++tp] = x; proc[x] = 1; for(auto p: edge[x]){ int y = p.first; if(p.second == id) continue; if(!disc[y]){ tarjan(y, p.second); low[x] = min(low[x], low[y]); } else if(proc[y]) low[x] = min(low[x], disc[y]); } if(disc[x] == low[x]){ int y; ++cnt; do{ y = stck[tp--]; proc[y] = 0; color[y] = cnt; }while(y != x); } } void dfs(int x, int fa){ disc[x] = -1; for(auto p: e[x]){ int y = p.first, id = p.second; if(y == fa) continue; dfs(y, x); w[x] += w[y]; if(!w[y]) ans[id] = 'B'; else if(w[y] > 0) ans[id] = (node[id] == pii(y, x)) ? 'R' : 'L'; else ans[id] = (node[id] == pii(x, y)) ? 'R' : 'L'; } } int main() { #ifdef LOCAL_DEFINE freopen("input.txt", "r", stdin); #endif cin >> n >> m; int x, y; for(int i = 1; i <= m; i++){ cin >> x >> y; node[i] = pii(x, y); edge[x].push_back(pii(y, i)); edge[y].push_back(pii(x, i)); } for(int i = 1; i <= n; i++) if (!disc[i]) tarjan(i, 0); for (int i = 1; i <= m; i++){ if (color[node[i].first] == color[node[i].second]){ ans[i] = 'B'; continue; } x = color[node[i].first], y = color[node[i].second]; e[x].push_back(pii(y, i)); e[y].push_back(pii(x, i)); node[i] = pii(x, y); } int qq; cin >> qq; while(qq--){ cin >> x >> y; if(color[x] == color[y]) continue; x = color[x], y = color[y]; w[x]++, w[y]--; } for(int i = 1; i <= n; i++) if(disc[i] >= 0) dfs(i, 0); for(int i = 1; i <= m; i++) cout << ans[i]; }

Compilation message (stderr)

oneway.cpp: In function 'void usaco(std::string)':
oneway.cpp:33:10: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
   33 |   freopen((s+".in").c_str(), "r", stdin);
      |   ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
oneway.cpp:34:10: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
   34 |   freopen((s+".out").c_str(), "w", stdout);
      |   ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...