답안 #1055451

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1055451 2024-08-12T19:41:13 Z trMatherz One-Way Streets (CEOI17_oneway) C++17
60 / 100
3000 ms 11720 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); 
    }
    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)]--; 
        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]; 
        }
    }
    //F(i, n) 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 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 1 ms 428 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 1 ms 344 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 1 ms 444 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 1 ms 428 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 1 ms 344 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 1 ms 444 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 33 ms 4808 KB Output is correct
12 Correct 37 ms 6092 KB Output is correct
13 Correct 45 ms 6856 KB Output is correct
14 Correct 46 ms 8900 KB Output is correct
15 Correct 52 ms 9672 KB Output is correct
16 Correct 49 ms 10688 KB Output is correct
17 Correct 74 ms 11208 KB Output is correct
18 Correct 55 ms 10736 KB Output is correct
19 Correct 92 ms 11720 KB Output is correct
20 Correct 55 ms 6856 KB Output is correct
21 Correct 37 ms 6912 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 1 ms 428 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 1 ms 344 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 1 ms 444 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 33 ms 4808 KB Output is correct
12 Correct 37 ms 6092 KB Output is correct
13 Correct 45 ms 6856 KB Output is correct
14 Correct 46 ms 8900 KB Output is correct
15 Correct 52 ms 9672 KB Output is correct
16 Correct 49 ms 10688 KB Output is correct
17 Correct 74 ms 11208 KB Output is correct
18 Correct 55 ms 10736 KB Output is correct
19 Correct 92 ms 11720 KB Output is correct
20 Correct 55 ms 6856 KB Output is correct
21 Correct 37 ms 6912 KB Output is correct
22 Execution timed out 3054 ms 11204 KB Time limit exceeded
23 Halted 0 ms 0 KB -