답안 #702229

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
702229 2023-02-23T10:45:01 Z SamNguyen One-Way Streets (CEOI17_oneway) C++14
60 / 100
802 ms 262144 KB
#include <bits/stdc++.h>
using namespace std;

#define INPFILE "CEOI17_oneway.inp"
#define OUTFILE "CEOI17_oneway.out"

template <class T1, class T2>
inline bool minimise(T1 &x, T2 y) {
    if (x > y) { x = y; return true; }
    return false;
}

template <class T1, class T2>
inline bool maximise(T1 &x, T2 y) {
    if (x < y) { x = y; return true; }
    return false;
}

class Tree {
private:
    int n;
    vector<vector<tuple<int, int, bool>>> adj;
    vector<pair<int, int>> par;
    vector<pair<int, bool>> reqs;

//    void dfs(int u = 0, int p = -1) {
//        for (const auto &e : adj[u]) {
//            int v = e.first;
//            if (v == p) {
//                par[v] = e;
//                continue;
//            }
//            dfs(v, u);
//        }
//    }
//
//

    bool dfs_dir(int u, int y, int p = -1) {
//        cerr << "dfs_dir " << u << " " << y << endl;

        if (u == y)
            return true;

        for (const auto &e : adj[u]) {
            int v, i; bool dir;
            tie(v, i, dir) = e;
            if (v == p)
                continue;

            if (dfs_dir(v, y, u)) {
                reqs.emplace_back(i, dir);
                return true;
            }
        }

        return false;
    }

public:
    Tree() {}
    Tree(int n): n(n) {
        adj.assign(n, vector<tuple<int, int, bool>>());
    }

    inline void add_edge(int u, int v, int i) {
        adj[u].emplace_back(v, i, true);
        adj[v].emplace_back(u, i, false);
    }

    void traverse() {
//        par.assign(n, make_pair(-1, -1));
//        dfs();
    }

    inline void set_dir(int x, int y) {
        dfs_dir(x, y);
    }

    template <class Func>
    inline void FOR_REQS(Func f) {
        for (const auto &e : reqs)
            f(e.first, e.second);
    }
};

const int MAX = 1e5 + 7;
int N, M, P;
vector<pair<int, int>> edges;
vector<int> adj[MAX];
vector<pair<int, int>> dirs;

inline int OTHER_NODE(int i, int u) {
    return edges[i].first ^ edges[i].second ^ u;
}

void input() {
    cin >> N >> M;
    for (int t = M; t--; ) {
        int u, v; cin >> u >> v;
        adj[u].push_back(edges.size());
        adj[v].push_back(edges.size());
        edges.emplace_back(u, v);
    }

    cin >> P;
    for (int t = P; t--; ) {
        int x, y; cin >> x >> y;
        dirs.emplace_back(x, y);
    }
}

int COUNTER, tin[MAX], low[MAX], root[MAX], comp[MAX];
int COUNT_BCCS;
stack<int> st;
bool on_stack[MAX];

void dfs(int u, int pi = -1) {
    tin[u] = low[u] = ++COUNTER;
    st.push(u);
    on_stack[u] = true;

    for (int i : adj[u]) if (i != pi) {
        int v = OTHER_NODE(i, u);
        if (tin[v] == 0) {
            dfs(v, i);
            minimise(low[u], low[v]);
        }
        else
            minimise(low[u], tin[v]);
    }

    if (low[u] == tin[u]) {
        while (true) {
            int v = st.top(); st.pop();
            on_stack[v] = false;
            root[v] = u;
            comp[v] = COUNT_BCCS;
            if (v == u)
                break;
        }

        COUNT_BCCS++;
    }
}

Tree tree;

void init() {
    COUNTER = COUNT_BCCS = 0;
    memset(tin, 0, sizeof tin);
    for (int u = 1; u <= N; u++) if (tin[u] == 0)
        dfs(u);

    tree = Tree(COUNT_BCCS);

    for (int i = 0; i < M; i++) {
        int u, v;
        tie(u, v) = edges[i];
        if (comp[u] == comp[v])
            continue;
        tree.add_edge(comp[u], comp[v], i);
    }

    tree.traverse();
}

void solve() {
    for (const auto &p : dirs) {
        int x, y;
        tie(x, y) = p;
        tree.set_dir(comp[x], comp[y]);
    }

    string ans(M, 'B');

    tree.FOR_REQS([&](int i, bool dir) {
        ans[i] = (dir ? 'R' : 'L');
    });

    cout << ans;
}

int main(void) {
    if (fopen(INPFILE, "r")) {
        freopen(INPFILE, "r", stdin);
        freopen(OUTFILE, "w", stdout);
    }

    input();
    init();
    solve();

    return 0;
}

Compilation message

oneway.cpp: In function 'int main()':
oneway.cpp:186:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
  186 |         freopen(INPFILE, "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~
oneway.cpp:187:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
  187 |         freopen(OUTFILE, "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 3028 KB Output is correct
2 Correct 2 ms 3028 KB Output is correct
3 Correct 2 ms 3028 KB Output is correct
4 Correct 2 ms 3284 KB Output is correct
5 Correct 4 ms 3544 KB Output is correct
6 Correct 2 ms 3028 KB Output is correct
7 Correct 4 ms 3540 KB Output is correct
8 Correct 4 ms 3156 KB Output is correct
9 Correct 3 ms 3028 KB Output is correct
10 Correct 2 ms 3112 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 3028 KB Output is correct
2 Correct 2 ms 3028 KB Output is correct
3 Correct 2 ms 3028 KB Output is correct
4 Correct 2 ms 3284 KB Output is correct
5 Correct 4 ms 3544 KB Output is correct
6 Correct 2 ms 3028 KB Output is correct
7 Correct 4 ms 3540 KB Output is correct
8 Correct 4 ms 3156 KB Output is correct
9 Correct 3 ms 3028 KB Output is correct
10 Correct 2 ms 3112 KB Output is correct
11 Correct 69 ms 8084 KB Output is correct
12 Correct 67 ms 9088 KB Output is correct
13 Correct 81 ms 10408 KB Output is correct
14 Correct 91 ms 12476 KB Output is correct
15 Correct 99 ms 13364 KB Output is correct
16 Correct 116 ms 16156 KB Output is correct
17 Correct 163 ms 33912 KB Output is correct
18 Correct 153 ms 16220 KB Output is correct
19 Correct 217 ms 35164 KB Output is correct
20 Correct 66 ms 9012 KB Output is correct
21 Correct 66 ms 9336 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 3028 KB Output is correct
2 Correct 2 ms 3028 KB Output is correct
3 Correct 2 ms 3028 KB Output is correct
4 Correct 2 ms 3284 KB Output is correct
5 Correct 4 ms 3544 KB Output is correct
6 Correct 2 ms 3028 KB Output is correct
7 Correct 4 ms 3540 KB Output is correct
8 Correct 4 ms 3156 KB Output is correct
9 Correct 3 ms 3028 KB Output is correct
10 Correct 2 ms 3112 KB Output is correct
11 Correct 69 ms 8084 KB Output is correct
12 Correct 67 ms 9088 KB Output is correct
13 Correct 81 ms 10408 KB Output is correct
14 Correct 91 ms 12476 KB Output is correct
15 Correct 99 ms 13364 KB Output is correct
16 Correct 116 ms 16156 KB Output is correct
17 Correct 163 ms 33912 KB Output is correct
18 Correct 153 ms 16220 KB Output is correct
19 Correct 217 ms 35164 KB Output is correct
20 Correct 66 ms 9012 KB Output is correct
21 Correct 66 ms 9336 KB Output is correct
22 Runtime error 802 ms 262144 KB Execution killed with signal 9
23 Halted 0 ms 0 KB -