답안 #1027269

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1027269 2024-07-19T03:01:23 Z anHiep One-Way Streets (CEOI17_oneway) C++14
30 / 100
20 ms 11728 KB
#include<bits/stdc++.h>
#ifdef LOCAL
#include "D:\debug.h"
#else
#define cebug(...) "Orz_chUoNgnn_khanhtb_0x2ee08"
#endif

using namespace std;

#define fi first 
#define se second
#define pb push_back
#define ll long long
#define ii pair<int, int>
#define vi vector<int> 
#define vll vector<ll>
#define vii vector<ii>
#define cd complex<double>
const ll mod = 1e9 + 7;
const ll INF = 1e18L + 5;
const double PI = acos(-1);
const int block = 320;
const int N = 2e5;
int tc, tt = 1;

int n, m, u, v, p;
ii ans[N + 5];

struct edge {
    int v, id, x, y;
};
vector<edge> g[N + 5];
vii e;

namespace sub1 {
    bool ck() {
        return n <= 1000 && m <= 1000 && p <= 100;
    }

    int tin[1005], tout[1005], low[1005], tdfs = 0;
    int vis[1005];
    int comp[1005], curcomp = 0;
    bool bridge[1005];
    int s, t;
    vector<edge> adj[1005];

    void find_bridge(int u ,int par) {
        tin[u] = low[u] = ++tdfs;
        vis[u] = true;
        for(auto v: g[u])
            if(v.v != par) {
                if(!vis[v.v]) {
                    find_bridge(v.v, u);
                    low[u] = min(low[u], low[v.v]);
                    if(low[v.v] > tin[u])
                        bridge[v.id] = true;
                }
                else low[u] = min(low[u], tin[v.v]);
            }
        tout[u] = tdfs;
    }

    void find_comp(int u, int par) {
        vis[u] = true;
        comp[u] = curcomp;
        for(auto v: g[u])
            if(v.v != par && !vis[v.v] && !bridge[v.id])
                find_comp(v.v, u);
     }

    bool dfs(int u, int par) {
        vis[u] = true;
        if(u == comp[t]) return true;
        for(auto v: adj[u])
            if(v.v != par) {
                if(dfs(v.v, u)) {
                    if(bridge[v.id]) ans[v.id] = {v.x, v.y};
                    return true;
                }
            }
        return false;
    }

    void sol() {
        memset(vis, 0, sizeof(vis));
        for(int i=1; i<=n; i++)
            if(!vis[i]) {
                tdfs = 0;
                find_bridge(i, -1);
            }
        memset(vis, 0, sizeof(vis));
        for(int i=1; i<=n; i++)
            if(!vis[i]) {
                curcomp++;
                find_comp(i, -1);
            }
        for(int i=1; i<=n; i++) cerr<<i<<' '<<comp[i]<<'\n';
        for(int i=1; i<=m; i++)
            if(bridge[i]) {
                int u = e[i - 1].fi;
                int v = e[i - 1].se;
                if(comp[u] != comp[v]) {
                    adj[comp[u]].pb({comp[v], i, u, v});
                    adj[comp[v]].pb({comp[u], i, v, u});
                }
            }
        cin>>p;
        for(int i=1; i<=p; i++) {
            cin>>s>>t;
            memset(vis, 0, sizeof(vis));
            dfs(comp[s], -1);
        }
        for(int i=1; i<=m; i++) {
            if(ans[i].fi < 0 || !bridge[i]) {
                cout<<"B";
            }
            else {
                cout<<(ans[i] == e[i - 1] ? "R" : "L");
            }
        }
    }
}

void solve() {
    cin>>n>>m;
    for(int i=1; i<=m; i++) {
        cin>>u>>v;
        ans[i] = {-1, -1};
        e.pb({u, v});
        g[u].pb({v, i, -1, -1});
        g[v].pb({u, i, -1, -1});
    }
    if(sub1::ck()) {sub1::sol(); return;}
}
signed main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    for(tc=1; tc<=tt; tc++) solve();
    cerr<<"\nTime elapsed: "<<1000.0*clock()/CLOCKS_PER_SEC<<" ms.\n";
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 5212 KB Output is correct
2 Correct 1 ms 5212 KB Output is correct
3 Correct 4 ms 5212 KB Output is correct
4 Correct 6 ms 5212 KB Output is correct
5 Correct 6 ms 5212 KB Output is correct
6 Correct 4 ms 5212 KB Output is correct
7 Correct 7 ms 5304 KB Output is correct
8 Correct 7 ms 5280 KB Output is correct
9 Correct 5 ms 5212 KB Output is correct
10 Correct 3 ms 5212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 5212 KB Output is correct
2 Correct 1 ms 5212 KB Output is correct
3 Correct 4 ms 5212 KB Output is correct
4 Correct 6 ms 5212 KB Output is correct
5 Correct 6 ms 5212 KB Output is correct
6 Correct 4 ms 5212 KB Output is correct
7 Correct 7 ms 5304 KB Output is correct
8 Correct 7 ms 5280 KB Output is correct
9 Correct 5 ms 5212 KB Output is correct
10 Correct 3 ms 5212 KB Output is correct
11 Incorrect 20 ms 11728 KB Output isn't correct
12 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 5212 KB Output is correct
2 Correct 1 ms 5212 KB Output is correct
3 Correct 4 ms 5212 KB Output is correct
4 Correct 6 ms 5212 KB Output is correct
5 Correct 6 ms 5212 KB Output is correct
6 Correct 4 ms 5212 KB Output is correct
7 Correct 7 ms 5304 KB Output is correct
8 Correct 7 ms 5280 KB Output is correct
9 Correct 5 ms 5212 KB Output is correct
10 Correct 3 ms 5212 KB Output is correct
11 Incorrect 20 ms 11728 KB Output isn't correct
12 Halted 0 ms 0 KB -