Submission #1112214

# Submission time Handle Problem Language Result Execution time Memory
1112214 2024-11-13T19:56:20 Z mariaclara One-Way Streets (CEOI17_oneway) C++17
100 / 100
79 ms 16532 KB
#include<bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef pair<int,int> pii;
const int MAXN = 1e5 + 5;
#define all(x) x.begin(), x.end();
#define sz(x) (int)x.size()
#define mk make_pair 
#define pb push_back 
#define fr first 
#define sc second 

int n, m, p, up_edge[MAXN], ponte[MAXN], val[MAXN];
int niv[MAXN], vis[MAXN];
int A[MAXN], B[MAXN], S[MAXN], E[MAXN];
vector<pii> edges[MAXN];
string ans;

int dfs(int x, int up_edge) {
    vis[x] = 1;

    int lower_back = n;
    for(auto [viz, ind] : edges[x]) {
        if(!vis[viz]) {
            niv[viz] = niv[x] + 1;

            lower_back = min(lower_back, dfs(viz, ind));
        }
        else if(ind != up_edge) lower_back = min(lower_back, niv[viz]);
    }

    if(lower_back >= niv[x]) ponte[x] = 1;
    return lower_back;
}

int calc_ans(int x, int up_edge) {
    vis[x] = 1;

    int at_val = val[x];
    for(auto [viz, ind] : edges[x]) {
        if(!vis[viz])
            at_val += calc_ans(viz, ind);
    }

    if(at_val > 0 and ponte[x]) {
        if(A[up_edge] == x) ans[up_edge] = 'R';
        else ans[up_edge] = 'L';
    }

    if(at_val < 0 and ponte[x]) {
        if(A[up_edge] == x) ans[up_edge] = 'L';
        else ans[up_edge] = 'R';
    }

    return at_val;
}
int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);

    cin >> n >> m;

    for(int i = 0; i < m; i++) {
        cin >> A[i] >> B[i];
        edges[A[i]].pb({B[i], i});
        edges[B[i]].pb({A[i], i});
        ans += 'B';
    }

    cin >> p;
    
    for(int i = 1; i <= p; i++)
        cin >> S[i] >> E[i], val[S[i]]++, val[E[i]]--;

    for(int i = 1; i <= n; i++)
        if(!vis[i]) dfs(i, -1), ponte[i] = 0;

    memset(vis, 0, sizeof(vis));
    for(int i = 1; i <= n; i++)
        if(!vis[i]) calc_ans(i, 0);

    cout << ans;
}
# Verdict Execution time Memory Grader output
1 Correct 2 ms 4688 KB Output is correct
2 Correct 2 ms 4916 KB Output is correct
3 Correct 2 ms 4860 KB Output is correct
4 Correct 2 ms 4688 KB Output is correct
5 Correct 3 ms 4688 KB Output is correct
6 Correct 2 ms 4688 KB Output is correct
7 Correct 2 ms 4856 KB Output is correct
8 Correct 2 ms 4688 KB Output is correct
9 Correct 2 ms 4688 KB Output is correct
10 Correct 2 ms 4688 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 4688 KB Output is correct
2 Correct 2 ms 4916 KB Output is correct
3 Correct 2 ms 4860 KB Output is correct
4 Correct 2 ms 4688 KB Output is correct
5 Correct 3 ms 4688 KB Output is correct
6 Correct 2 ms 4688 KB Output is correct
7 Correct 2 ms 4856 KB Output is correct
8 Correct 2 ms 4688 KB Output is correct
9 Correct 2 ms 4688 KB Output is correct
10 Correct 2 ms 4688 KB Output is correct
11 Correct 35 ms 9044 KB Output is correct
12 Correct 30 ms 11080 KB Output is correct
13 Correct 35 ms 12144 KB Output is correct
14 Correct 48 ms 12808 KB Output is correct
15 Correct 42 ms 12716 KB Output is correct
16 Correct 76 ms 10568 KB Output is correct
17 Correct 32 ms 12396 KB Output is correct
18 Correct 65 ms 10884 KB Output is correct
19 Correct 34 ms 13648 KB Output is correct
20 Correct 46 ms 10412 KB Output is correct
21 Correct 33 ms 10320 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 4688 KB Output is correct
2 Correct 2 ms 4916 KB Output is correct
3 Correct 2 ms 4860 KB Output is correct
4 Correct 2 ms 4688 KB Output is correct
5 Correct 3 ms 4688 KB Output is correct
6 Correct 2 ms 4688 KB Output is correct
7 Correct 2 ms 4856 KB Output is correct
8 Correct 2 ms 4688 KB Output is correct
9 Correct 2 ms 4688 KB Output is correct
10 Correct 2 ms 4688 KB Output is correct
11 Correct 35 ms 9044 KB Output is correct
12 Correct 30 ms 11080 KB Output is correct
13 Correct 35 ms 12144 KB Output is correct
14 Correct 48 ms 12808 KB Output is correct
15 Correct 42 ms 12716 KB Output is correct
16 Correct 76 ms 10568 KB Output is correct
17 Correct 32 ms 12396 KB Output is correct
18 Correct 65 ms 10884 KB Output is correct
19 Correct 34 ms 13648 KB Output is correct
20 Correct 46 ms 10412 KB Output is correct
21 Correct 33 ms 10320 KB Output is correct
22 Correct 67 ms 13520 KB Output is correct
23 Correct 73 ms 11920 KB Output is correct
24 Correct 79 ms 12160 KB Output is correct
25 Correct 79 ms 16532 KB Output is correct
26 Correct 56 ms 13160 KB Output is correct
27 Correct 55 ms 12208 KB Output is correct
28 Correct 25 ms 8256 KB Output is correct
29 Correct 55 ms 11092 KB Output is correct
30 Correct 49 ms 11492 KB Output is correct
31 Correct 56 ms 11736 KB Output is correct
32 Correct 45 ms 13700 KB Output is correct