Submission #897027

# Submission time Handle Problem Language Result Execution time Memory
897027 2024-01-02T12:34:55 Z codefox One-Way Streets (CEOI17_oneway) C++14
100 / 100
122 ms 20444 KB
#include <bits/stdc++.h>

using namespace std;

#define pii pair<int, int>
#define s second
#define f first

vector<vector<pii>> graph;
vector<vector<pii>> cgraph;
vector<int> comp;
vector<int> low;
vector<int> num;
vector<bool> used;
vector<int> start;
vector<int> ende;
vector<int> dir;
vector<bool> vis;
stack<int> s;
int c = 0;
int d = 0;

void bicc(int i)
{
    vis[i] = true;
    low[i] = num[i] = c++;
    s.push(i);
    for (pii ele: graph[i])
    {
        if (used[ele.s]) continue;
        used[ele.s] = true;
        if (!vis[ele.f]) bicc(ele.f);
        low[i] = min(low[i], low[ele.f]);
    }
    if (num[i]==low[i])
    {
        while (s.size() && num[s.top()]>=num[i])
        {
            comp[s.top()] = d;
            s.pop();
        }
        d++;
    }
}

int dfs(int i)
{
    vis[i] = true;
    int path = 0;
    path -= ende[i];
    path +=start[i];
    for (pii ele:cgraph[i])
    {
        if (vis[ele.f]) continue;
        dir[ele.s] = dfs(ele.f);
        path += dir[ele.s];
        if (dir[ele.s]<0) dir[ele.s] = ele.f;
        else if (dir[ele.s]>0) dir[ele.s] = i;
        else dir[ele.s] = -1;
    }
    return path;
}


int main()
{
    int n, m;
    cin >> n >> m;
    graph = vector<vector<pii>>(n);
    comp = vector<int>(n);
    low = vector<int>(n);
    num = vector<int>(n);
    used = vector<bool>(m, false);
    vis  = vector<bool>(n, false);
    vector<pii> edges(m);
    for (int i = 0; i < m; i++)
    {
        int a, b;
        cin >> a >> b;
        a--; b--;
        graph[a].push_back({b, i});
        graph[b].push_back({a, i});
        edges[i] = {a, b};
    }
    for (int i = 0; i < n; i++) if (!vis[i]) bicc(i);

    cgraph = vector<vector<pii>>(d);
    for (int i = 0; i < n; i++)
    {
        for (pii ele: graph[i])
        {
            if (comp[i]==comp[ele.f]) continue;
            cgraph[comp[i]].push_back({comp[ele.f], ele.s});
        }
    }

    start = vector<int>(d, 0);
    ende = vector<int>(d, 0);
    dir = vector<int>(m, -1);
    vis = vector<bool>(d, false);

    int t;
    cin >> t;
    while (t--)
    {
        int a, b;
        cin >> a >> b;
        a--; b--;
        start[comp[a]]++;
        ende[comp[b]]++;
    }

    for (int i = 0; i < d; i++)
    {
        if (vis[i]) continue;
        dfs(i);
    }

    for (int i = 0; i < m; i++)
    {
        if (dir[i]==-1) cout << 'B';
        else if (dir[i]==comp[edges[i].s]) cout << 'R';
        else if (dir[i]==comp[edges[i].f]) cout << 'L';
    }

    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 1 ms 604 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 1 ms 604 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 1 ms 604 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 1 ms 604 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 52 ms 6224 KB Output is correct
12 Correct 57 ms 7512 KB Output is correct
13 Correct 66 ms 9040 KB Output is correct
14 Correct 67 ms 11600 KB Output is correct
15 Correct 71 ms 12652 KB Output is correct
16 Correct 76 ms 15876 KB Output is correct
17 Correct 87 ms 17180 KB Output is correct
18 Correct 97 ms 16052 KB Output is correct
19 Correct 83 ms 18552 KB Output is correct
20 Correct 59 ms 7504 KB Output is correct
21 Correct 58 ms 7248 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 1 ms 604 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 1 ms 604 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 52 ms 6224 KB Output is correct
12 Correct 57 ms 7512 KB Output is correct
13 Correct 66 ms 9040 KB Output is correct
14 Correct 67 ms 11600 KB Output is correct
15 Correct 71 ms 12652 KB Output is correct
16 Correct 76 ms 15876 KB Output is correct
17 Correct 87 ms 17180 KB Output is correct
18 Correct 97 ms 16052 KB Output is correct
19 Correct 83 ms 18552 KB Output is correct
20 Correct 59 ms 7504 KB Output is correct
21 Correct 58 ms 7248 KB Output is correct
22 Correct 122 ms 17256 KB Output is correct
23 Correct 117 ms 15440 KB Output is correct
24 Correct 117 ms 15808 KB Output is correct
25 Correct 119 ms 20444 KB Output is correct
26 Correct 116 ms 16784 KB Output is correct
27 Correct 121 ms 15700 KB Output is correct
28 Correct 55 ms 3672 KB Output is correct
29 Correct 97 ms 7248 KB Output is correct
30 Correct 117 ms 7164 KB Output is correct
31 Correct 105 ms 7532 KB Output is correct
32 Correct 108 ms 11600 KB Output is correct