답안 #860090

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
860090 2023-10-11T15:22:20 Z hariaakas646 One-Way Streets (CEOI17_oneway) C++17
0 / 100
1 ms 344 KB
#include <bits/stdc++.h>

using namespace std;

#define scd(t) scanf("%d", &t)
#define sclld(t) scanf("%lld", &t)
#define forr(i, j, k) for (int i = j; i < k; i++)
#define frange(i, j) forr(i, 0, j)
#define all(cont) cont.begin(), cont.end()
#define mp make_pair
#define pb push_back
#define f first
#define s second
typedef long long int lli;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<bool> vb;
typedef vector<lli> vll;
typedef vector<string> vs;
typedef vector<pii> vii;
typedef vector<vi> vvi;
typedef map<int, int> mpii;
typedef set<int> seti;
typedef multiset<int> mseti;
typedef long double ld;


void usaco()
{
    freopen("/media/hariaakash646/785EF1075EF0BF46/CompetitiveProgramming/input.in", "r", stdin);
//    freopen("problem.out", "w", stdout);
}

vector<vii> graph;
vii edge;
vb dfstree;
vb vis;

void dfs(int x) {
    vis[x] = true;
    for(auto e : graph[x]) {
        if(!vis[e.f]) {
            dfstree[e.s] = true;
            dfs(e.f);
        }
    }
} 

vb bridg;
vector<vii> tree;
vb on;
int c = 0;

void dfs2(int x, int p) {
    for(auto e : graph[x]) {
        if(!dfstree[e.s]) {
            if(!on[e.s]) {
                on[e.s] = true;
                c++;
            }
            else {
                on[e.s] = false;
                c--;
            }
        }
    }

    for(auto e : tree[x]) {
        if(e.f != p) {
            if(c) bridg[e.s] = false;
            dfs2(e.f, x);
        }
    }
}

vi out;

vii val;
vi en, st;

void assg(int a, int b, int id) {
    if(edge[id].f == a) out[id] = 1;
    else out[id] = -1;
}

int dfs3(int x, int p) {
    int c1 = 0;
    c1 += st[x];
    c1 -= en[x];

    for(auto e : tree[x]) {
        if(e.f != p) {
            int v = dfs3(e.f, x);

            if(bridg[e.s]) {if(v > 0) {
                            assg(e.f, x, e.s);
                        }
                        else if(v < 0) assg(x, e.f, e.s);}
            c1 += v;
        }
    }
    return c1;
}

int main() {
    // usaco();
    int n, m, p;
    scd(n);
    scd(m);
    

    graph = vector<vii>(n+1);
    dfstree = vb(m);
    edge = vii(m);

    frange(i, m) {
        int a, b;
        scd(a);
        scd(b);
        graph[a].pb(mp(b, i));
        graph[b].pb(mp(a, i));
        edge[i] = mp(a, b);
    }

    vis = vb(n+1);
    dfs(1);

    bridg = vb(m);
    tree = vector<vii>(n+1);
    frange(i, m) {
        if(dfstree[i]) {
            int a= edge[i].f;
            int b = edge[i].s;
            tree[a].pb(mp(b, i));
            tree[b].pb(mp(a, i));
            bridg[i] = true;
        }
    }

    on = vb(m);
    dfs2(1, 0);

    // frange(i, m) {
    //     if(bridg[i]) printf("%d %d\n", edge[i].f, edge[i].s);
    // }

    val = vii(p);
    st = en = vi(n+1);
    scd(p);
    frange(i, p) {
        scd(val[i].f);
        scd(val[i].s);
        st[val[i].f]++;
        en[val[i].s]++;
    }

    out = vi(m);
    dfs3(1, 0);
    for(auto e : out) {
        if(e == 1) printf("R");
        else if(e == -1) printf("L");
        else printf("B");
    }
}

Compilation message

oneway.cpp: In function 'void usaco()':
oneway.cpp:30:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   30 |     freopen("/media/hariaakash646/785EF1075EF0BF46/CompetitiveProgramming/input.in", "r", stdin);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
oneway.cpp: In function 'int main()':
oneway.cpp:5:21: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
    5 | #define scd(t) scanf("%d", &t)
      |                ~~~~~^~~~~~~~~~
oneway.cpp:108:5: note: in expansion of macro 'scd'
  108 |     scd(n);
      |     ^~~
oneway.cpp:5:21: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
    5 | #define scd(t) scanf("%d", &t)
      |                ~~~~~^~~~~~~~~~
oneway.cpp:109:5: note: in expansion of macro 'scd'
  109 |     scd(m);
      |     ^~~
oneway.cpp:5:21: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
    5 | #define scd(t) scanf("%d", &t)
      |                ~~~~~^~~~~~~~~~
oneway.cpp:118:9: note: in expansion of macro 'scd'
  118 |         scd(a);
      |         ^~~
oneway.cpp:5:21: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
    5 | #define scd(t) scanf("%d", &t)
      |                ~~~~~^~~~~~~~~~
oneway.cpp:119:9: note: in expansion of macro 'scd'
  119 |         scd(b);
      |         ^~~
oneway.cpp:5:21: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
    5 | #define scd(t) scanf("%d", &t)
      |                ~~~~~^~~~~~~~~~
oneway.cpp:149:5: note: in expansion of macro 'scd'
  149 |     scd(p);
      |     ^~~
oneway.cpp:5:21: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
    5 | #define scd(t) scanf("%d", &t)
      |                ~~~~~^~~~~~~~~~
oneway.cpp:151:9: note: in expansion of macro 'scd'
  151 |         scd(val[i].f);
      |         ^~~
oneway.cpp:5:21: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
    5 | #define scd(t) scanf("%d", &t)
      |                ~~~~~^~~~~~~~~~
oneway.cpp:152:9: note: in expansion of macro 'scd'
  152 |         scd(val[i].s);
      |         ^~~
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 344 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 344 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 344 KB Output isn't correct
2 Halted 0 ms 0 KB -