Submission #390286

# Submission time Handle Problem Language Result Execution time Memory
390286 2021-04-15T19:02:21 Z mchang One-Way Streets (CEOI17_oneway) C++11
0 / 100
4 ms 6476 KB
#define pb push_back
#define eb emplace_back
#define F first
#define S second

#include <bits/stdc++.h>

using namespace std;

typedef pair<int,int> pii;


vector<pii> adj[1<<18];
char dir[1<<18];
vector<pii> edges;

int pre[1<<18];
int link[1<<18];
int prenum = 1;

int N,M,P;
int indeg[1<<18];
int outdeg[1<<18];

void dfs(int u, int pi) {
    pre[u] = link[u] = prenum++;
    int minlink = pre[u];

    for (auto& e : adj[u]) {
        if (e.S == pi) continue;
        int v = e.F;

        if (pre[v] == 0) {
            dfs(v, e.S);
            indeg[u]+=indeg[v];
            outdeg[u]+=outdeg[v];
        }

        minlink = min(minlink, link[v]);
    }
    link[u] = minlink;

    int deg = outdeg[u]-indeg[u];
    if (deg < 0) {
        // need more coming in from above
        // pi needs to go from parent->u
        if (edges[pi].S == u) dir[pi] = 'R';
        else dir[pi] = 'L';

    } else if (deg > 0) {
        // there are nodes above me that need me
        // need to go from u->parent
        if (edges[pi].F == u) dir[pi] = 'R';
        else dir[pi] = 'L';
    }
}



int main() {
    scanf("%d %d", &N, &M);
    for (int i = 0; i < M; i++) {
        int u,v;
        scanf("%d %d", &u, &v);
        adj[u].eb(v, i);
        adj[v].eb(u, i);
        dir[i] = 'B';
        edges.eb(u,v);
    }

    scanf("%d", &P);
    for (int i = 0; i < P; i++) {
        int u,v; scanf("%d %d", &u, &v);
        outdeg[u]++;
        indeg[v]++;
    }

    for (int u = 1; u <= N; u++) {
        if (pre[u] == 0) {
            dfs(u, -1);
        }
    }

    for (int i = 0; i < M; i++) {
        /* printf("%c", dir[i]); */
        cout << dir[i];
    }
    cout << endl;

}


Compilation message

oneway.cpp: In function 'int main()':
oneway.cpp:61:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   61 |     scanf("%d %d", &N, &M);
      |     ~~~~~^~~~~~~~~~~~~~~~~
oneway.cpp:64:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   64 |         scanf("%d %d", &u, &v);
      |         ~~~~~^~~~~~~~~~~~~~~~~
oneway.cpp:71:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   71 |     scanf("%d", &P);
      |     ~~~~~^~~~~~~~~~
oneway.cpp:73:23: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   73 |         int u,v; scanf("%d %d", &u, &v);
      |                  ~~~~~^~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Incorrect 4 ms 6476 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 4 ms 6476 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 4 ms 6476 KB Output isn't correct
2 Halted 0 ms 0 KB -