Submission #1055441

# Submission time Handle Problem Language Result Execution time Memory
1055441 2024-08-12T19:32:52 Z trMatherz One-Way Streets (CEOI17_oneway) C++17
0 / 100
0 ms 344 KB
#include <iostream>
 
// #include <fstream>
// std::ifstream cin ("sprinklers2.in");
// std::ofstream cout ("sprinklers2.out");
 
 
// includes
#include <cmath>
#include <set>
#include <map>
#include <queue>
#include <string>
#include <vector>
#include <array>
#include <algorithm>
#include <numeric>
#include <iomanip>
#include <unordered_set>
#include <stack>
#include <ext/pb_ds/assoc_container.hpp>
#include <random>
#include <chrono>
#include <bitset>
#include <complex>
 
// usings
using namespace std;
using namespace __gnu_pbds;
 
// misc
#define ll long long
#define ld long double
#define pb push_back
#define pq priority_queue
#define ub upper_bound
#define lb lower_bound
template <typename T, typename U>
bool emin(T &a, const U &b) { return b < a ? a = b, true : false; }
template <typename T, typename U>
bool emax(T &a, const U &b) { return b > a ? a = b, true : false; }
typedef uint64_t hash_t;
 
// vectors
#define vi vector<int>
#define vvi vector<vi>
#define vvvi vector<vvi>
#define vpii vector<pair<int, int>>
#define vvpii vector<vector<pair<int, int>>>
#define vppipi vector<pair<int, pair<int, int>>>
#define vl vector<ll>
#define vvl vector<vl>
#define vvvl vector<vvl>
#define vpll vector<pair<ll, ll>>
#define vvpll vector<vpll>
#define vb vector<bool>
#define vvb vector<vb>
#define vs vector<string>
#define sz(x) (int)x.size()
#define rz resize
#define all(x) x.begin(), x.end()
#define vc vector<char>
#define vvc vector<vc>
 
// pairs
#define pii pair<int, int>
#define pll pair<ll, ll>
#define mp make_pair
#define f first
#define s second
 
// sets
#define si set<int>
#define sl set<ll>
#define ss set<string>
#define in insert
template <class T>
using iset = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
 
// maps
#define mii map<int, int>
#define mll map<ll, ll>

// loops
#define FR(x, z, y) for (int x = z; x < y; x++)
#define FRE(x, z, y) FR(x, z, y + 1)
#define F(x, y) FR(x, 0, y)
#define FE(x, y) F(x, y + 1)
#define A(x, y) for (auto &x : y)




struct TwoEdgeCC {
    struct { 
        vi a; 
        void init(int n) { a = vi(n, -1); }
        int get(int x) { return a[x] < 0 ? x : a[x] = get(a[x]); }
        bool merge(int x, int y) {
            x = get(x), y = get(y); if(x == y) return false; 
            a[x] += a[y]; a[y] = x; return true; 
        }
    } dsu; 
    int n; vvpii a; vi b, d, p; vpii e; 
    void init(int tn) { n = tn, a = vvpii(n), b = d = vi(n), p = vi(n, -1), dsu.init(tn); }
    void dfs(int x) { A(u, a[x]) if(u.f != p[x]) b[u.f] = u.s, p[u.f] = x, d[u.f] = d[x] + 1, dfs(u.f); }
    void ae(int x, int y, int z) { if(dsu.merge(x, y)) a[x].pb({y, z}), a[y].pb({x, z}); else e.pb({x, y}); }
    void ad(int x, int y) {
        while(true) {
            x = dsu.get(x), y = dsu.get(y); if(x == y) return; 
            if(d[x] < d[y]) swap(x, y); 
            dsu.merge(p[x], x); 
        }
    }
    void go() {
        F(i, n) if(p[i] == -1) dfs(i); 
        dsu.init(n); 
        A(u, e) ad(u.f, u.s); 
    }
};
TwoEdgeCC a; 
vi c, ans; 
void plop(int x, int y){
    A(u, a.a[x]) {
        if(u.f == y) continue; 
        plop(u.f, x); 
    }
    ans[a.b[a.dsu.get(x)]] = c[x];
    c[a.p[x]] += c[x]; 
}
int main() {
    int n, m; cin >> n >> m; ans = vi(m, 0); 
    vpii b; c = vi(n, 0); 
    a.init(n); 
    F(i, m){
        int x, y; cin >> x >> y; x--; y--; 
        a.ae(x, y, i); b.pb({x, y}); 
    }
    a.go(); 
    int p; cin >> p;
    F(i, p){
        int x, y; cin >> x >> y; x--; y--;
        c[a.dsu.get(x)]++; c[a.dsu.get(y)]--; 
        // while(true) {
        //     x = a.dsu.get(x), y = a.dsu.get(y); if(x == y) break; 
        //     if(a.d[x] < a.d[y]) swap(x, y), v *= -1; 
        //     ans[a.b[x]] = v; x = a.p[x]; 
        // }
    }
    plop(0, 0); 
    int cur = 0;
    A(u, ans){
        if(a.d[b[cur].f] < a.d[b[cur].s]) {
            if(u == 0) cout << "B";
            else if(u > 0) cout << "L"; 
            else cout << "R";   
        } else {
            if(u == 0) cout << "B";
            else if(u < 0) cout << "L"; 
            else cout << "R"; 
        }
        cur++; 
    }

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