답안 #162299

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
162299 2019-11-07T14:05:36 Z karma One-Way Streets (CEOI17_oneway) C++14
100 / 100
138 ms 28184 KB
#include <bits/stdc++.h>
#define pb          emplace_back
#define ll          long long
#define fi          first
#define se          second
#define mp          make_pair

using namespace std;

const int N = int(2e5) + 7;

typedef pair<int, int> pii;
struct TEdge{int u, v; bool del;} e[N];
int low[N], num[N], Time = 0, br[N], lab[N], cnt = 0;
vector<int> ver, a[N];
vector<pii> g[N];
int n, m, u, v, q, c[N], f[N], vis[N];
string s;

void DFS(int u) {
    low[u] = num[u] = ++Time;
    for(int i: a[u]) {
       if(e[i].del) continue;
       e[i].del = 1;
       int v = e[i].u ^ e[i].v ^ u;
       if(!num[v]) {
         int cur = ver.size();
         DFS(v);
         low[u] = min(low[u], low[v]);
         if(low[v] >= num[v]) {
            br[i] = 1; ++cnt;
            while(int(ver.size()) > cur) lab[ver.back()] = cnt, ver.pop_back();
         }
       } else low[u] = min(low[u], num[v]);
    }
    ver.pb(u);
}

void dfs(int u) {
    vis[u] = 1;
    for(auto lst: g[u]) {
        if(vis[lst.fi]) continue;
        dfs(lst.fi);
        f[u] += f[lst.fi];
        if(f[lst.fi] < 0) s[lst.se - 1] = (lab[e[lst.se].u] == u? 'R': 'L');
        if(f[lst.fi] == 0) s[lst.se - 1] = 'B';
        if(f[lst.fi] > 0) s[lst.se - 1] = (lab[e[lst.se].u] == u? 'L': 'R');
    }
}

int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0), cout.tie(0);
    #define Task        "test"
    if(fopen(Task".inp", "r")) {
        freopen(Task".inp", "r", stdin);
        freopen(Task".out", "w", stdout);
    }
    cin >> n >> m;
    for(int i = 1; i <= m; ++i) {
        cin >> u >> v;
        a[u].pb(i), a[v].pb(i);
        e[i] = {u, v, 0};
    }
    for(int i = 1; i <= n; ++i) {
        if(!lab[i]) {
            DFS(i); ++cnt;
            while(ver.size()) lab[ver.back()] = cnt, ver.pop_back();
        }
    }
    cin >> q;
    while(q --) {
        cin >> u >> v;
        ++c[u], --c[v];
    }
    s.resize(m);
    for(int i = 1; i <= m; ++i) {
        if(!br[i]) s[i - 1] = 'B';
        g[lab[e[i].u]].pb(mp(lab[e[i].v], i));
        g[lab[e[i].v]].pb(mp(lab[e[i].u], i));
    }
    for(int i = 1; i <= n; ++i) f[lab[i]] += c[i];
    for(int i = 1; i <= n; ++i)
        if(!vis[i]) dfs(i);
    cout << s;
}

Compilation message

oneway.cpp: In function 'int main()':
oneway.cpp:56:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
         freopen(Task".inp", "r", stdin);
         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
oneway.cpp:57:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
         freopen(Task".out", "w", stdout);
         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 11 ms 9848 KB Output is correct
2 Correct 11 ms 9720 KB Output is correct
3 Correct 12 ms 9848 KB Output is correct
4 Correct 11 ms 9976 KB Output is correct
5 Correct 12 ms 9976 KB Output is correct
6 Correct 11 ms 9976 KB Output is correct
7 Correct 11 ms 9976 KB Output is correct
8 Correct 11 ms 9948 KB Output is correct
9 Correct 14 ms 9848 KB Output is correct
10 Correct 20 ms 9848 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 11 ms 9848 KB Output is correct
2 Correct 11 ms 9720 KB Output is correct
3 Correct 12 ms 9848 KB Output is correct
4 Correct 11 ms 9976 KB Output is correct
5 Correct 12 ms 9976 KB Output is correct
6 Correct 11 ms 9976 KB Output is correct
7 Correct 11 ms 9976 KB Output is correct
8 Correct 11 ms 9948 KB Output is correct
9 Correct 14 ms 9848 KB Output is correct
10 Correct 20 ms 9848 KB Output is correct
11 Correct 64 ms 17388 KB Output is correct
12 Correct 91 ms 19000 KB Output is correct
13 Correct 84 ms 20116 KB Output is correct
14 Correct 89 ms 21544 KB Output is correct
15 Correct 98 ms 21868 KB Output is correct
16 Correct 125 ms 21624 KB Output is correct
17 Correct 103 ms 23412 KB Output is correct
18 Correct 121 ms 21980 KB Output is correct
19 Correct 102 ms 24828 KB Output is correct
20 Correct 77 ms 18524 KB Output is correct
21 Correct 69 ms 18936 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 11 ms 9848 KB Output is correct
2 Correct 11 ms 9720 KB Output is correct
3 Correct 12 ms 9848 KB Output is correct
4 Correct 11 ms 9976 KB Output is correct
5 Correct 12 ms 9976 KB Output is correct
6 Correct 11 ms 9976 KB Output is correct
7 Correct 11 ms 9976 KB Output is correct
8 Correct 11 ms 9948 KB Output is correct
9 Correct 14 ms 9848 KB Output is correct
10 Correct 20 ms 9848 KB Output is correct
11 Correct 64 ms 17388 KB Output is correct
12 Correct 91 ms 19000 KB Output is correct
13 Correct 84 ms 20116 KB Output is correct
14 Correct 89 ms 21544 KB Output is correct
15 Correct 98 ms 21868 KB Output is correct
16 Correct 125 ms 21624 KB Output is correct
17 Correct 103 ms 23412 KB Output is correct
18 Correct 121 ms 21980 KB Output is correct
19 Correct 102 ms 24828 KB Output is correct
20 Correct 77 ms 18524 KB Output is correct
21 Correct 69 ms 18936 KB Output is correct
22 Correct 138 ms 24568 KB Output is correct
23 Correct 137 ms 23040 KB Output is correct
24 Correct 135 ms 23160 KB Output is correct
25 Correct 129 ms 28184 KB Output is correct
26 Correct 137 ms 24340 KB Output is correct
27 Correct 122 ms 23160 KB Output is correct
28 Correct 53 ms 15464 KB Output is correct
29 Correct 93 ms 19532 KB Output is correct
30 Correct 91 ms 19704 KB Output is correct
31 Correct 96 ms 19944 KB Output is correct
32 Correct 109 ms 22904 KB Output is correct