Submission #952486

#TimeUsernameProblemLanguageResultExecution timeMemory
952486_callmelucianOne-Way Streets (CEOI17_oneway)C++14
0 / 100
2024 ms2792 KiB
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef long double ld; typedef pair<ll,ll> pl; typedef pair<int,int> pii; typedef tuple<int,int,int> tt; #define all(a) a.begin(), a.end() #define filter(a) a.erase(unique(all(a)), a.end()) const int mn = 1e5 + 5; vector<int> adj[mn]; bool vis[mn]; void dfs (int u) { if (vis[u]) return; vis[u] = 1; for (int v : adj[u]) dfs(v); } int main() { ios::sync_with_stdio(0); cin.tie(0); int n, m; cin >> n >> m; vector<int> ans(m); // 0: none, 1: left, 2: right, 3: both vector<pii> edge(m); for (int i = 0; i < m; i++) { int a, b; cin >> a >> b; edge[i] = {a, b}; } int p; cin >> p; vector<pii> cond(p); for (int i = 0; i < p; i++) { int a, b; cin >> a >> b; cond[i] = {a, b}; } for (int mask = 0; mask < (1 << m); mask++) { for (int i = 1; i <= n; i++) adj[i].clear(); for (int i = 0; i < m; i++) { int a, b; tie(a, b) = edge[i]; if (mask & (1 << i)) adj[a].push_back(b); // right else adj[b].push_back(a); // left } bool flg = 1; for (pii it : cond) { for (int i = 1; i <= n; i++) vis[i] = 0; dfs(it.first); if (!vis[it.second]) flg = 0; } if (flg) { for (int i = 0; i < m; i++) { if (mask & (1 << i)) { if (ans[i] == 0 || ans[i] == 2) ans[i] = 2; else if (ans[i] == 1) ans[i] = 3; } else { if (ans[i] == 0 || ans[i] == 1) ans[i] = 1; else if (ans[i] == 2) ans[i] = 3; } } } } for (int i = 0; i < m; i++) { if (ans[i] == 1) cout << 'L'; else if (ans[i] == 2) cout << 'R'; else cout << 'B'; } return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...