Submission #367632

# Submission time Handle Problem Language Result Execution time Memory
367632 2021-02-17T19:21:45 Z Sparky_09 One-Way Streets (CEOI17_oneway) C++17
100 / 100
233 ms 22508 KB
#include "bits/stdc++.h"
using namespace std;
#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define all(x) begin(x), end(x)
#define trav(a, x) for(auto& a : x)
#define sz(x) (int)(x).size()
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<pii> vpi;

template <class T>
void rd(T &x) {
	int sgn = 1;
	char ch;
	x = 0;
	for (ch = getchar(); (ch < '0' || ch > '9') && ch != '-'; ch = getchar()) ;
	if (ch == '-') ch = getchar(), sgn = -1;
	for (; '0' <= ch && ch <= '9'; ch = getchar()) x = x * 10 + ch - '0';
	x *= sgn;
}
template <class T>
void wr(T x) {
	if (x < 0) putchar('-'), wr(-x);
	else if (x < 10) putchar(x + '0');
	else wr(x / 10), putchar(x % 10 + '0');
}

template<class T> bool ckmin(T& a, const T& b) { return a > b ? a = b, 1 : 0; }
template<class T> bool ckmax(T& a, const T& b) { return a < b ? a = b, 1 : 0; }

void usaco(string s){
  freopen((s+".in").c_str(), "r", stdin);
  freopen((s+".out").c_str(), "w", stdout);
}

pii node[100010];
vector<pii> edge[100010], e[100010];
int n, m, disc[100010], low[100010], tot, stck[100010], tp, color[100010], cnt, w[100010];
bool proc[100010];
char ans[100010];

void tarjan(int x, int id){
    disc[x] = low[x] = ++tot;
    stck[++tp] = x;
    proc[x] = 1;
    for(auto p: edge[x]){
        int y = p.first;
        if(p.second == id)
            continue;
        if(!disc[y]){
            tarjan(y, p.second);
            low[x] = min(low[x], low[y]);
        } 
        else if(proc[y])
            low[x] = min(low[x], disc[y]);
    }
    if(disc[x] == low[x]){
        int y;
        ++cnt;
        do{
            y = stck[tp--];
            proc[y] = 0;
            color[y] = cnt;
        }while(y != x);
    }
}


void dfs(int x, int fa){
    disc[x] = -1;
    for(auto p: e[x]){
        int y = p.first, id = p.second;
        if(y == fa)
            continue;
        dfs(y, x);
        w[x] += w[y];
        if(!w[y])
            ans[id] = 'B';
        else if(w[y] > 0)
            ans[id] = (node[id] == pii(y, x)) ? 'R' : 'L';
        else
            ans[id] = (node[id] == pii(x, y)) ? 'R' : 'L';
    }
}


int main() {
#ifdef LOCAL_DEFINE
	freopen("input.txt", "r", stdin);
#endif
    cin >> n >> m;
    int x, y;
    for(int i = 1; i <= m; i++){
        cin >> x >> y;
        node[i] = pii(x, y);
        edge[x].push_back(pii(y, i));
        edge[y].push_back(pii(x, i));
    }
    for(int i = 1; i <= n; i++)
        if (!disc[i])
            tarjan(i, 0);
    for (int i = 1; i <= m; i++){
        if (color[node[i].first] == color[node[i].second]){
            ans[i] = 'B';
            continue;
        }
        x = color[node[i].first], y = color[node[i].second];
        e[x].push_back(pii(y, i));
        e[y].push_back(pii(x, i));
        node[i] = pii(x, y);
    }
    int qq;
    cin >> qq;
    while(qq--){
        cin >> x >> y;
        if(color[x] == color[y]) continue;
        x = color[x], y = color[y];
        w[x]++, w[y]--;
    }
    for(int i = 1; i <= n; i++)
        if(disc[i] >= 0)
            dfs(i, 0);
    for(int i = 1; i <= m; i++) cout << ans[i];
}

Compilation message

oneway.cpp: In function 'void usaco(std::string)':
oneway.cpp:33:10: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
   33 |   freopen((s+".in").c_str(), "r", stdin);
      |   ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
oneway.cpp:34:10: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
   34 |   freopen((s+".out").c_str(), "w", stdout);
      |   ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 4 ms 5100 KB Output is correct
2 Correct 4 ms 5100 KB Output is correct
3 Correct 4 ms 5100 KB Output is correct
4 Correct 5 ms 5100 KB Output is correct
5 Correct 5 ms 5228 KB Output is correct
6 Correct 5 ms 5248 KB Output is correct
7 Correct 5 ms 5228 KB Output is correct
8 Correct 5 ms 5100 KB Output is correct
9 Correct 4 ms 5100 KB Output is correct
10 Correct 4 ms 5100 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 5100 KB Output is correct
2 Correct 4 ms 5100 KB Output is correct
3 Correct 4 ms 5100 KB Output is correct
4 Correct 5 ms 5100 KB Output is correct
5 Correct 5 ms 5228 KB Output is correct
6 Correct 5 ms 5248 KB Output is correct
7 Correct 5 ms 5228 KB Output is correct
8 Correct 5 ms 5100 KB Output is correct
9 Correct 4 ms 5100 KB Output is correct
10 Correct 4 ms 5100 KB Output is correct
11 Correct 82 ms 11500 KB Output is correct
12 Correct 90 ms 12268 KB Output is correct
13 Correct 103 ms 13676 KB Output is correct
14 Correct 116 ms 14828 KB Output is correct
15 Correct 115 ms 15208 KB Output is correct
16 Correct 128 ms 16364 KB Output is correct
17 Correct 111 ms 17772 KB Output is correct
18 Correct 167 ms 16364 KB Output is correct
19 Correct 109 ms 19180 KB Output is correct
20 Correct 88 ms 12012 KB Output is correct
21 Correct 87 ms 11756 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 5100 KB Output is correct
2 Correct 4 ms 5100 KB Output is correct
3 Correct 4 ms 5100 KB Output is correct
4 Correct 5 ms 5100 KB Output is correct
5 Correct 5 ms 5228 KB Output is correct
6 Correct 5 ms 5248 KB Output is correct
7 Correct 5 ms 5228 KB Output is correct
8 Correct 5 ms 5100 KB Output is correct
9 Correct 4 ms 5100 KB Output is correct
10 Correct 4 ms 5100 KB Output is correct
11 Correct 82 ms 11500 KB Output is correct
12 Correct 90 ms 12268 KB Output is correct
13 Correct 103 ms 13676 KB Output is correct
14 Correct 116 ms 14828 KB Output is correct
15 Correct 115 ms 15208 KB Output is correct
16 Correct 128 ms 16364 KB Output is correct
17 Correct 111 ms 17772 KB Output is correct
18 Correct 167 ms 16364 KB Output is correct
19 Correct 109 ms 19180 KB Output is correct
20 Correct 88 ms 12012 KB Output is correct
21 Correct 87 ms 11756 KB Output is correct
22 Correct 178 ms 19052 KB Output is correct
23 Correct 189 ms 17388 KB Output is correct
24 Correct 233 ms 17516 KB Output is correct
25 Correct 172 ms 22508 KB Output is correct
26 Correct 174 ms 18668 KB Output is correct
27 Correct 183 ms 17388 KB Output is correct
28 Correct 95 ms 9324 KB Output is correct
29 Correct 144 ms 12652 KB Output is correct
30 Correct 143 ms 12820 KB Output is correct
31 Correct 148 ms 13164 KB Output is correct
32 Correct 155 ms 16236 KB Output is correct