Submission #1055466

# Submission time Handle Problem Language Result Execution time Memory
1055466 2024-08-12T19:48:54 Z trMatherz One-Way Streets (CEOI17_oneway) C++17
60 / 100
3000 ms 14844 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, 0), 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); 
    }
    if(x == a.dsu.get(x)) c[a.dsu.get(a.p[x])] += c[x], ans[a.b[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 = vi(n, 0); 
        c[a.dsu.get(x)]++; c[a.dsu.get(y)]--; 
        F(i, n) if(a.d[i] == 0) plop(i, i); 
        // int v = 1; 
        // 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]; 
        // }
    }
    
    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 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 2 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 2 ms 348 KB Output is correct
8 Correct 1 ms 440 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 2 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 2 ms 348 KB Output is correct
8 Correct 1 ms 440 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 74 ms 5328 KB Output is correct
12 Correct 112 ms 6340 KB Output is correct
13 Correct 185 ms 7308 KB Output is correct
14 Correct 314 ms 9412 KB Output is correct
15 Correct 370 ms 10244 KB Output is correct
16 Correct 65 ms 11144 KB Output is correct
17 Correct 352 ms 13492 KB Output is correct
18 Correct 396 ms 11192 KB Output is correct
19 Correct 354 ms 14844 KB Output is correct
20 Correct 163 ms 7228 KB Output is correct
21 Correct 136 ms 7912 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 2 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 2 ms 348 KB Output is correct
8 Correct 1 ms 440 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 74 ms 5328 KB Output is correct
12 Correct 112 ms 6340 KB Output is correct
13 Correct 185 ms 7308 KB Output is correct
14 Correct 314 ms 9412 KB Output is correct
15 Correct 370 ms 10244 KB Output is correct
16 Correct 65 ms 11144 KB Output is correct
17 Correct 352 ms 13492 KB Output is correct
18 Correct 396 ms 11192 KB Output is correct
19 Correct 354 ms 14844 KB Output is correct
20 Correct 163 ms 7228 KB Output is correct
21 Correct 136 ms 7912 KB Output is correct
22 Execution timed out 3027 ms 13672 KB Time limit exceeded
23 Halted 0 ms 0 KB -