Submission #394851

# Submission time Handle Problem Language Result Execution time Memory
394851 2021-04-27T11:18:33 Z Noureldin One-Way Streets (CEOI17_oneway) C++14
100 / 100
148 ms 21924 KB
#pragma GCC optimize ("O3")
#include <bits/stdc++.h>
#define loop(i,n) for(int i = 0;i < (n);i++)
#define all(A) A.begin(),A.end()
#define pb push_back
#define mp make_pair
#define sz(A) ((int)A.size())
typedef std::vector<int> vi;
typedef std::pair<int,int> pi;
typedef std::vector<pi> vp;
typedef long long ll;
#define popcnt(x) __builtin_popcount(x)
#define LSOne(x) ((x) & (-(x)))
#define print(A,t) cerr << #A << ": "; copy(all(A),ostream_iterator<t>(cerr," " )); cerr << endl
#define prArr(A,n,t)  cerr << #A << ": "; copy(A,A + n,ostream_iterator<t>(cerr," " )); cerr << endl
#define PRESTDIO() cin.tie(0),cerr.tie(0),ios_base::sync_with_stdio(0)
#define what_is(x) cerr << #x << " is " << x << endl
#define bit_lg(x) (assert(x > 0),__builtin_ffsll(x) - 1)
const double PI = acos(-1);
template<class A,class B>
std::ostream& operator << (std::ostream& st,const std::pair<A,B> p) {
	st << "(" << p.first << ", " << p.second << ")";
	return st;
}
void tc();
auto test_cases = []() {
	int T; scanf("%d", &T);
	while(T--) tc();
};
using namespace std;

const int MAXN = 100*1000 + 10;
int dfs_num[MAXN], dfs_low[MAXN], dfs_time;
list<int> E[MAXN];
vi fr, to;
vector<bool> isBridge;
int n, m, p;

void dfs(int u, int ie){
	dfs_low[u] = dfs_num[u] = dfs_time++;
	for(int e : E[u]) if(e != ie) {
		int v = fr[e] + to[e] - u;
		if(dfs_num[v] == -1){
			dfs(v, e);
			if(dfs_low[v] > dfs_num[u]) {
				isBridge[e] = true;
			}
			dfs_low[u] = min(dfs_low[u], dfs_low[v]);
		} else {
			dfs_low[u] = min(dfs_low[u], dfs_num[v]);
		}
	}
}

int id[MAXN], W[MAXN];
int find(int a){
	return id[a] = (a == id[a]) ? a : find(id[a]);
}
void join(int a, int b){
	a = find(a);
	b = find(b);
	if(a == b) return;
	if(W[a] < W[b]) swap(a, b);
	W[a] += W[b];
	id[b] = a;
	E[a].splice(E[a].end(), E[b]);
}



int val[MAXN], depth[MAXN];
vi edgeVal;

int dfs3(int u, int p){
	depth[u] = depth[p] + 1;
	int ret = val[u];
	dfs_num[u] = 1;
	for(int e : E[u]) {
		int v = find(fr[e]) + find(to[e]) - u;
		if(v == p) continue;
		int tmp = dfs3(v, u);
		edgeVal[e] = tmp;
		ret += tmp;
	}
	return ret;
}

int main(){
#ifdef HOME
	freopen("in.in", "r", stdin);
#endif
	scanf("%d %d", &n, &m);
	loop(e, m){
		int a, b; scanf("%d %d", &a, &b);
		fr.push_back(a);
		to.push_back(b);
		isBridge.push_back(false);
		E[a].push_back(e);
		E[b].push_back(e);
	}
	memset(dfs_num, -1, sizeof dfs_num);
	for(int i = 1; i <= n; i++) if(dfs_num[i] == -1) dfs(i, -1);
	fill(W, W + n + 1, 1);
	iota(id, id + n + 1, 0);
	loop(e, m) if(!isBridge[e]) join(fr[e], to[e]);
	vi V;
	for(int i = 1; i <= n; i++) if(i == find(i)) V.push_back(i);
	list<int> aux;
	for(int i : V){
		aux.clear();
		for(int e : E[i]) if(isBridge[e]){
			aux.push_back(e);
		}
		E[i].swap(aux);
	}

	edgeVal.resize(m, 0);
	scanf("%d", &p);
	while(p--){
		int a, b; scanf("%d %d", &a, &b);
		a = find(a), b = find(b);
		if(a == b) continue;
		val[a]++;
		val[b]--;
	}
	memset(dfs_num, -1, sizeof dfs_num);
	for(int i : V) if(dfs_num[i] == -1) dfs3(i, 0);

	loop(e, m) {
		if(!isBridge[e] || edgeVal[e] == 0) putchar('B');
		else {
			int a0 = find(fr[e]), b0 = find(to[e]);
			int a = a0, b = b0;
			if(depth[a] > depth[b]) swap(a, b);
			if(edgeVal[e] > 0) swap(a, b);
			putchar("LR"[a == a0]);
		}
	}
	puts("");
	return 0;
}

Compilation message

oneway.cpp: In function 'int main()':
oneway.cpp:92:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   92 |  scanf("%d %d", &n, &m);
      |  ~~~~~^~~~~~~~~~~~~~~~~
oneway.cpp:94:18: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   94 |   int a, b; scanf("%d %d", &a, &b);
      |             ~~~~~^~~~~~~~~~~~~~~~~
oneway.cpp:118:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  118 |  scanf("%d", &p);
      |  ~~~~~^~~~~~~~~~
oneway.cpp:120:18: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  120 |   int a, b; scanf("%d %d", &a, &b);
      |             ~~~~~^~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 2 ms 3020 KB Output is correct
2 Correct 3 ms 3020 KB Output is correct
3 Correct 3 ms 3148 KB Output is correct
4 Correct 3 ms 3148 KB Output is correct
5 Correct 4 ms 3164 KB Output is correct
6 Correct 3 ms 3148 KB Output is correct
7 Correct 4 ms 3180 KB Output is correct
8 Correct 3 ms 3176 KB Output is correct
9 Correct 3 ms 3148 KB Output is correct
10 Correct 3 ms 3148 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 3020 KB Output is correct
2 Correct 3 ms 3020 KB Output is correct
3 Correct 3 ms 3148 KB Output is correct
4 Correct 3 ms 3148 KB Output is correct
5 Correct 4 ms 3164 KB Output is correct
6 Correct 3 ms 3148 KB Output is correct
7 Correct 4 ms 3180 KB Output is correct
8 Correct 3 ms 3176 KB Output is correct
9 Correct 3 ms 3148 KB Output is correct
10 Correct 3 ms 3148 KB Output is correct
11 Correct 68 ms 13300 KB Output is correct
12 Correct 79 ms 14320 KB Output is correct
13 Correct 99 ms 15520 KB Output is correct
14 Correct 104 ms 16436 KB Output is correct
15 Correct 113 ms 16668 KB Output is correct
16 Correct 123 ms 13776 KB Output is correct
17 Correct 95 ms 16568 KB Output is correct
18 Correct 125 ms 14084 KB Output is correct
19 Correct 92 ms 18088 KB Output is correct
20 Correct 68 ms 13488 KB Output is correct
21 Correct 59 ms 13808 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 3020 KB Output is correct
2 Correct 3 ms 3020 KB Output is correct
3 Correct 3 ms 3148 KB Output is correct
4 Correct 3 ms 3148 KB Output is correct
5 Correct 4 ms 3164 KB Output is correct
6 Correct 3 ms 3148 KB Output is correct
7 Correct 4 ms 3180 KB Output is correct
8 Correct 3 ms 3176 KB Output is correct
9 Correct 3 ms 3148 KB Output is correct
10 Correct 3 ms 3148 KB Output is correct
11 Correct 68 ms 13300 KB Output is correct
12 Correct 79 ms 14320 KB Output is correct
13 Correct 99 ms 15520 KB Output is correct
14 Correct 104 ms 16436 KB Output is correct
15 Correct 113 ms 16668 KB Output is correct
16 Correct 123 ms 13776 KB Output is correct
17 Correct 95 ms 16568 KB Output is correct
18 Correct 125 ms 14084 KB Output is correct
19 Correct 92 ms 18088 KB Output is correct
20 Correct 68 ms 13488 KB Output is correct
21 Correct 59 ms 13808 KB Output is correct
22 Correct 138 ms 17684 KB Output is correct
23 Correct 140 ms 15388 KB Output is correct
24 Correct 148 ms 15272 KB Output is correct
25 Correct 117 ms 21924 KB Output is correct
26 Correct 122 ms 17168 KB Output is correct
27 Correct 147 ms 15544 KB Output is correct
28 Correct 77 ms 11692 KB Output is correct
29 Correct 88 ms 14092 KB Output is correct
30 Correct 84 ms 14912 KB Output is correct
31 Correct 109 ms 14620 KB Output is correct
32 Correct 99 ms 17768 KB Output is correct