답안 #906055

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

using namespace std;

const int mxN = 1e5+2;
map<int, int> eidx[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) 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 Incorrect 5 ms 15964 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 5 ms 15964 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 5 ms 15964 KB Output isn't correct
2 Halted 0 ms 0 KB -