답안 #906056

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
906056 2024-01-13T12:49:00 Z Pekiban One-Way Streets (CEOI17_oneway) C++17
100 / 100
231 ms 53088 KB
#include <bits/stdc++.h>

using namespace std;

const int mxN = 1e5+2;
map<int, int> eidx[mxN];
map<int, bool> visi[mxN];
vector<int> g[mxN], dfsg[mxN], upe[mxN], doe[mxN];
int dep[mxN], dp[mxN], parent[mxN], isbridge[mxN];
bool visited[mxN];
void dfsinit(int s, int e) {
    visited[s] = 1; 
    for (auto u : g[s]) {
        if (visited[u]) {
            if (u == e && !visi[s][u]) {
                visi[s][u] = 1;
                continue;
            }
            if (dep[u] < dep[s]) {
                upe[s].push_back(u);
            }
            else {
                doe[s].push_back(u);
            }
            continue;
        }
        dfsg[s].push_back(u);
        dep[u] = dep[s] + 1, parent[u] = s;
        dfsinit(u, s);
        dp[s] += dp[u];
    }
}
void dfsbridge(int s, int e) {
    isbridge[s] = upe[s].size() - doe[s].size();
    for (auto u : dfsg[s]) {
        if (u == e) continue; // ovo ne bi trebalo ista da menja lol
        dfsbridge(u, s);
        isbridge[s] += isbridge[u];
    }
}
int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    int n, m, p;
    cin >> n >> m;
    vector<char> ans(m, 'B');
    pair<int, int> e[m];
    for (int i = 0; i < m; ++i) {
        int u, v;
        cin >> u >> v;
        --u, --v;
        e[i] = {u, v};
        if (u == v) continue;
        eidx[u][v] = eidx[v][u] = i;
        g[u].push_back(v), g[v].push_back(u);
    }
    cin >> p;
    while (p--) {
        int u, v;
        cin >> u >> v;
        u--, v--;
        dp[u]++, dp[v]--;
    }
    for (int i = 0; i < n; ++i) {
        if (!visited[i]) {
            parent[i] = i;
            dfsinit(i, -1);
            dfsbridge(i, -1);
        }
    }
    for (int i = 0; i < n; ++i) {
        // cout << i << " down: ";
        // for (auto j : doe[i])   cout << j << ' ';
        // cout << " up: ";
        // for (auto j : upe[i])   cout << j << ' ';
        // cout << '\n';
        if (isbridge[i] == 0 && parent[i] != i && dp[i] != 0) {
            ans[eidx[i][parent[i]]] = ((e[eidx[i][parent[i]]].first == i) ^ (dp[i] < 0) ? 'R' : 'L');
        }
    }
    for (auto c : ans)  cout << c;
    cout << '\n';
}
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 20568 KB Output is correct
2 Correct 6 ms 20572 KB Output is correct
3 Correct 7 ms 20828 KB Output is correct
4 Correct 7 ms 20828 KB Output is correct
5 Correct 7 ms 20824 KB Output is correct
6 Correct 7 ms 20824 KB Output is correct
7 Correct 7 ms 20828 KB Output is correct
8 Correct 7 ms 20828 KB Output is correct
9 Correct 7 ms 20828 KB Output is correct
10 Correct 8 ms 20744 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 20568 KB Output is correct
2 Correct 6 ms 20572 KB Output is correct
3 Correct 7 ms 20828 KB Output is correct
4 Correct 7 ms 20828 KB Output is correct
5 Correct 7 ms 20824 KB Output is correct
6 Correct 7 ms 20824 KB Output is correct
7 Correct 7 ms 20828 KB Output is correct
8 Correct 7 ms 20828 KB Output is correct
9 Correct 7 ms 20828 KB Output is correct
10 Correct 8 ms 20744 KB Output is correct
11 Correct 117 ms 38480 KB Output is correct
12 Correct 115 ms 40700 KB Output is correct
13 Correct 118 ms 43600 KB Output is correct
14 Correct 162 ms 45792 KB Output is correct
15 Correct 188 ms 45796 KB Output is correct
16 Correct 149 ms 41808 KB Output is correct
17 Correct 185 ms 45652 KB Output is correct
18 Correct 215 ms 41736 KB Output is correct
19 Correct 169 ms 47956 KB Output is correct
20 Correct 139 ms 42064 KB Output is correct
21 Correct 131 ms 41060 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 20568 KB Output is correct
2 Correct 6 ms 20572 KB Output is correct
3 Correct 7 ms 20828 KB Output is correct
4 Correct 7 ms 20828 KB Output is correct
5 Correct 7 ms 20824 KB Output is correct
6 Correct 7 ms 20824 KB Output is correct
7 Correct 7 ms 20828 KB Output is correct
8 Correct 7 ms 20828 KB Output is correct
9 Correct 7 ms 20828 KB Output is correct
10 Correct 8 ms 20744 KB Output is correct
11 Correct 117 ms 38480 KB Output is correct
12 Correct 115 ms 40700 KB Output is correct
13 Correct 118 ms 43600 KB Output is correct
14 Correct 162 ms 45792 KB Output is correct
15 Correct 188 ms 45796 KB Output is correct
16 Correct 149 ms 41808 KB Output is correct
17 Correct 185 ms 45652 KB Output is correct
18 Correct 215 ms 41736 KB Output is correct
19 Correct 169 ms 47956 KB Output is correct
20 Correct 139 ms 42064 KB Output is correct
21 Correct 131 ms 41060 KB Output is correct
22 Correct 208 ms 46928 KB Output is correct
23 Correct 166 ms 43600 KB Output is correct
24 Correct 231 ms 43172 KB Output is correct
25 Correct 186 ms 53088 KB Output is correct
26 Correct 184 ms 45908 KB Output is correct
27 Correct 178 ms 43656 KB Output is correct
28 Correct 44 ms 25304 KB Output is correct
29 Correct 142 ms 42400 KB Output is correct
30 Correct 175 ms 42824 KB Output is correct
31 Correct 199 ms 43092 KB Output is correct
32 Correct 159 ms 45472 KB Output is correct