답안 #287794

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
287794 2020-09-01T01:06:33 Z thomas_li One-Way Streets (CEOI17_oneway) C++17
100 / 100
119 ms 21464 KB
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/priority_queue.hpp>
using namespace std;
using ll = long long;
using ld = long double;
using vi = vector<int>;
using pi = pair<int, int>;
using pll = pair<ll, ll>;
constexpr int INF = 0x3f3f3f3f; constexpr ll LLINF = 0x3f3f3f3f3f3f3f3f;
#define db(x) { cerr << #x << " = " << x << endl; }
template <typename T> void _dbarr(T* a, size_t sz){ for(int i = 0; i < sz; i++) cerr << a[i] << " \n"[i == sz-1]; }
template <typename T> void _dbarr(vector<T> a, size_t sz){ for(int i = 0; i < sz; i++) cerr << a[i] << " \n"[i == sz-1]; }
#define dbarr(x, n) {cerr << #x << ": "; _dbarr((x),(n));}
#define all(x) begin(x), end(x)
#define pb push_back
#define eb emplace_back
#define mpr make_pair
#define fs first
#define sn second
const int MM = 1e5+5;
int n,m,p,comp[MM],diff[MM],disc[MM],x,ti,cid;
vector<pi> adj[MM],adj1[MM];
bool vis[MM], vis1[MM];
char ans[MM];
vector<int> st;
int go(int u){
    int low = disc[u]= ++ti;
    st.eb(u);
    for(auto[v,w] : adj[u]){
        w >>= 1;
        if(!vis[w]){
            vis[w] = 1;
            low = min(low,disc[v]?:go(v));
        }
    }
    if(low == disc[u]){
        cid++;
        do{
            x = st.back(), st.pop_back(); comp[x] = cid;
        }while(x != u);
    }
    return low;
}

void dfs(int u, int pa){
    vis1[u] = 1;
    for(auto[v,w] : adj1[u]){
        if(v == pa) continue;
        dfs(v,u); diff[u]+=diff[v];
        if(diff[v] < 0) ans[w>>1] = (w&1 ? 'L' : 'R');
        else if(diff[v] > 0) ans[w>>1] = (!(w&1) ? 'L' : 'R');
    }
}

int main(){
	cin.tie(0)->sync_with_stdio(0);
	//freopen("in.txt","r", stdin);
    cin >> n >> m;
    for(int i = 0, j = 0, u = 0, v = 0; i < m; i++){
        cin >> u >> v; ans[i] = 'B';
        adj[u].push_back({v,j++}); adj[v].push_back({u,j++});
    }
    for(int i = 1; i <= n; i++) if(!disc[i]) go(i);
    cin >> p;
    for(int i = 1; i <= p; i++){
        int u,v;
        cin >> u >> v;
        diff[comp[u]]++; diff[comp[v]]--;
    }
    for(int u = 1; u <= n; u++) for(auto&[v,w] : adj[u])
        if(comp[u] != comp[v])
            adj1[comp[u]].push_back({comp[v],w});
    for(int i = 1; i <= cid; i++) if(!vis1[i])
        dfs(i,-1);

    cout << ans << "\n";
}
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 4992 KB Output is correct
2 Correct 3 ms 4992 KB Output is correct
3 Correct 4 ms 5120 KB Output is correct
4 Correct 4 ms 5120 KB Output is correct
5 Correct 4 ms 5248 KB Output is correct
6 Correct 4 ms 5120 KB Output is correct
7 Correct 4 ms 5120 KB Output is correct
8 Correct 4 ms 5120 KB Output is correct
9 Correct 4 ms 5120 KB Output is correct
10 Correct 4 ms 5120 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 4992 KB Output is correct
2 Correct 3 ms 4992 KB Output is correct
3 Correct 4 ms 5120 KB Output is correct
4 Correct 4 ms 5120 KB Output is correct
5 Correct 4 ms 5248 KB Output is correct
6 Correct 4 ms 5120 KB Output is correct
7 Correct 4 ms 5120 KB Output is correct
8 Correct 4 ms 5120 KB Output is correct
9 Correct 4 ms 5120 KB Output is correct
10 Correct 4 ms 5120 KB Output is correct
11 Correct 53 ms 10232 KB Output is correct
12 Correct 46 ms 10872 KB Output is correct
13 Correct 58 ms 11776 KB Output is correct
14 Correct 81 ms 12908 KB Output is correct
15 Correct 76 ms 13300 KB Output is correct
16 Correct 94 ms 15232 KB Output is correct
17 Correct 81 ms 16504 KB Output is correct
18 Correct 94 ms 15224 KB Output is correct
19 Correct 82 ms 18168 KB Output is correct
20 Correct 46 ms 10744 KB Output is correct
21 Correct 44 ms 10488 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 4992 KB Output is correct
2 Correct 3 ms 4992 KB Output is correct
3 Correct 4 ms 5120 KB Output is correct
4 Correct 4 ms 5120 KB Output is correct
5 Correct 4 ms 5248 KB Output is correct
6 Correct 4 ms 5120 KB Output is correct
7 Correct 4 ms 5120 KB Output is correct
8 Correct 4 ms 5120 KB Output is correct
9 Correct 4 ms 5120 KB Output is correct
10 Correct 4 ms 5120 KB Output is correct
11 Correct 53 ms 10232 KB Output is correct
12 Correct 46 ms 10872 KB Output is correct
13 Correct 58 ms 11776 KB Output is correct
14 Correct 81 ms 12908 KB Output is correct
15 Correct 76 ms 13300 KB Output is correct
16 Correct 94 ms 15232 KB Output is correct
17 Correct 81 ms 16504 KB Output is correct
18 Correct 94 ms 15224 KB Output is correct
19 Correct 82 ms 18168 KB Output is correct
20 Correct 46 ms 10744 KB Output is correct
21 Correct 44 ms 10488 KB Output is correct
22 Correct 106 ms 17784 KB Output is correct
23 Correct 107 ms 16248 KB Output is correct
24 Correct 119 ms 16632 KB Output is correct
25 Correct 104 ms 21464 KB Output is correct
26 Correct 106 ms 17528 KB Output is correct
27 Correct 104 ms 16248 KB Output is correct
28 Correct 37 ms 8568 KB Output is correct
29 Correct 65 ms 11512 KB Output is correct
30 Correct 67 ms 11640 KB Output is correct
31 Correct 68 ms 11896 KB Output is correct
32 Correct 72 ms 14580 KB Output is correct