답안 #45451

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
45451 2018-04-14T06:55:12 Z nickyrio One-Way Streets (CEOI17_oneway) C++17
0 / 100
40 ms 47352 KB
#include <bits/stdc++.h>
#define FOR(i, a, b) for (int i = (a); i <= (b); ++i)
#define FORD(i, a, b) for (int i = (a); i >= (b); --i)
#define REP(i, a) for (int i = 0; i < (a); ++i)
#define DEBUG(x) { cerr << #x << '=' << x << endl; }
#define Arr(a, l, r) { cerr << #a << " = {"; FOR(_, l, r) cerr << ' ' << a[_]; cerr << "}\n"; }
#define N 1001000
#define pp pair<int, int>
#define endl '\n'
#define IO ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
#define taskname ""
#define bit(S, i) (((S) >> (i)) & 1)
using namespace std;

int n, m, p, Redge[N];
vector<pp> e[N], newE[N];
int num[N], low[N], cnt, mark[N], nBico;
stack<int> st;
char res[N];

void dfs(int u, int p) {
    num[u] = low[u] = ++cnt;
    st.push(u);
    for(pp x : e[u]) if (x.second != p) {
        int v = x.first;
        if (num[v] == 0) {
            dfs(v, x.second);
            low[u] = min(low[v], low[u]);
            if (low[v] >= num[v]) {
                ++nBico;
                while (true) {
                    int z = st.top(); st.pop();
                    mark[z] = nBico;
                    if (z == v) break;
                }
            }
        } else low[u] = min(low[u], num[v]);
    }
    if (p == -1) {
        ++nBico;
        while (true) {
            int z = st.top(); st.pop();
            mark[z] = nBico;
            if (z == u) break;
        }
    }
}

void NewGraph() {
    FOR(u, 1, n) {
        for (pp x : e[u]) if (mark[u] != mark[x.first]) {
            newE[mark[u]].push_back(pp(mark[x.first], x.second));
        }
    }
}
int w[N];

void dfs2(int u, int p) {
    for (pp x : newE[u]) if (x.second != p) {
        dfs2(x.first, x.second);
        w[u] += w[x.first];
        if (w[x.first] == 0) res[x.second] == 'B';
        else {
            if (w[x.first] > 0) {
                if (mark[Redge[x.second]] == u) res[x.second] = 'R';
                else res[x.second] = 'L';
            }
            else {
                if (mark[Redge[x.second]] == u) res[x.second] = 'L';
                else res[x.second] = 'R';
            }
        }
    }
}

void Solve() {
    cin >> p;
    REP(i, p) {
        int u, v;
        cin >> u >> v;
        if (mark[u] == mark[v]) continue;
        w[mark[u]]++;
        w[mark[v]]--;
    }
    FOR(i, 1, m) res[i] = 'B';
    dfs2(1, -1);
    FOR(i, 1, m) cout << res[i];
}
int main() {
    #ifdef NERO
    freopen("test.inp","r",stdin);
    freopen("test.out","w",stdout);
    double stime = clock();
    #else
        //freopen(taskname".inp","r",stdin);
        //freopen(taskname".out","w",stdout);
    #endif //NERO
    IO;
    cin >> n >> m;
    FOR(i, 1, m) {
        int u, v;
        cin >> u >> v;
        e[u].push_back(pp(v, i));
        e[v].push_back(pp(u, i));
        Redge[i] = v;
    }
    FOR(i, 1, n) if (num[i] == 0) dfs(i, -1);
    NewGraph();
    FOR(i, 1, n) cout << i << ' ' << mark[i] << '\n';
    Solve();
    #ifdef NERO
    double etime = clock();
    cerr << "Execution time: " << (etime - stime) / CLOCKS_PER_SEC * 1000 << " ms.\n";
    #endif // NERO
}

Compilation message

oneway.cpp: In function 'void dfs2(int, int)':
oneway.cpp:62:44: warning: statement has no effect [-Wunused-value]
         if (w[x.first] == 0) res[x.second] == 'B';
                              ~~~~~~~~~~~~~~^~~~~~
# 결과 실행 시간 메모리 Grader output
1 Incorrect 40 ms 47352 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 40 ms 47352 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 40 ms 47352 KB Output isn't correct
2 Halted 0 ms 0 KB -