Submission #696207

# Submission time Handle Problem Language Result Execution time Memory
696207 2023-02-05T21:26:18 Z Shayan86 One-Way Streets (CEOI17_oneway) C++14
0 / 100
2 ms 2644 KB
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef pair<ll, ll> pll;
typedef pair<int, int> pii;

#define Mp          make_pair
#define sep         ' '
#define F	        first
#define S	        second
#define pb          push_back
#define all(x)      (x).begin(),(x).end()
#define kill(res)	cout << res << '\n';
#define set_dec(x)	cout << fixed << setprecision(x);
#define fast_io     ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define file_io     freopen("input.txt", "r", stdin) ; freopen("output.txt", "w", stdout);

const ll N = 1e5 + 5;
const ll inf = 1e9 + 7;

ll n, m, q, sum[N], res[N];

bool mark[N];
vector<pair<int, pii>> adj[N];

void dfs(int v, pair<int, pii> ii = Mp(0, Mp(0, 0))){
    mark[v] = true;

    bool ch = true;
    for(auto e: adj[v]){
        int u = e.F;
        if(!mark[u]){
            dfs(u, e);
            sum[v] += sum[u];
        }
        else if(e.S.F != ii.S.F){
            ch = false;
        }
    }

    if(ch){
        bool up = sum[v] < 0;
        bool change = ii.S.S;
        if(up ^ change) res[ii.S.F] = 2;
        else res[ii.S.F] = 1;

        //cout << v << sep << up << sep << change << sep << (up ^ change) << endl;
    }
}

int main(){
    fast_io;

    cin >> n >> m;

    int u, v;
    for(int i = 1; i <= m; i++){
        cin >> u >> v;
        adj[u].pb(Mp(v, Mp(i, 0)));
        adj[v].pb(Mp(u, Mp(i, 1)));
    }

    cin >> q;

    for(int i = 1; i <= q; i++){
        cin >> u >> v;
        sum[u]++; sum[v]--;
    }

    for(int i = 1; i <= n; i++){
        if(!mark[i]){
            dfs(i);
        }
    }

    for(int i = 1; i <= m; i++){
        if(res[i] == 1)
            cout << 'L';
        else if(res[i] == 2)
            cout << 'R';
        else
            cout << 'B';
    }
    cout << endl;

}

# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 2644 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 2644 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 2644 KB Output isn't correct
2 Halted 0 ms 0 KB -