답안 #1055468

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1055468 2024-08-12T19:49:26 Z trMatherz One-Way Streets (CEOI17_oneway) C++17
100 / 100
86 ms 18240 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[a.dsu.get(x)]++; c[a.dsu.get(y)]--; 
    }
    F(i, n) if(a.d[i] == 0) plop(i, i); 
    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++; 
    }

    
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 34 ms 4244 KB Output is correct
12 Correct 37 ms 5324 KB Output is correct
13 Correct 42 ms 6096 KB Output is correct
14 Correct 55 ms 8236 KB Output is correct
15 Correct 52 ms 8904 KB Output is correct
16 Correct 52 ms 9928 KB Output is correct
17 Correct 49 ms 11840 KB Output is correct
18 Correct 53 ms 9868 KB Output is correct
19 Correct 51 ms 13484 KB Output is correct
20 Correct 43 ms 6068 KB Output is correct
21 Correct 38 ms 6404 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 34 ms 4244 KB Output is correct
12 Correct 37 ms 5324 KB Output is correct
13 Correct 42 ms 6096 KB Output is correct
14 Correct 55 ms 8236 KB Output is correct
15 Correct 52 ms 8904 KB Output is correct
16 Correct 52 ms 9928 KB Output is correct
17 Correct 49 ms 11840 KB Output is correct
18 Correct 53 ms 9868 KB Output is correct
19 Correct 51 ms 13484 KB Output is correct
20 Correct 43 ms 6068 KB Output is correct
21 Correct 38 ms 6404 KB Output is correct
22 Correct 86 ms 12620 KB Output is correct
23 Correct 85 ms 11840 KB Output is correct
24 Correct 80 ms 11844 KB Output is correct
25 Correct 76 ms 18240 KB Output is correct
26 Correct 77 ms 13624 KB Output is correct
27 Correct 76 ms 12100 KB Output is correct
28 Correct 38 ms 3612 KB Output is correct
29 Correct 70 ms 8228 KB Output is correct
30 Correct 66 ms 8320 KB Output is correct
31 Correct 68 ms 8192 KB Output is correct
32 Correct 71 ms 13284 KB Output is correct