답안 #1031888

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1031888 2024-07-23T08:27:24 Z samek08 One-Way Streets (CEOI17_oneway) C++14
100 / 100
95 ms 16964 KB
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(a,b) for (int a = 0; a < (b); ++a)
#define pb push_back
#define all(t) t.begin(), t.end()
 
struct Krawedz
{
	int a,b;
};
 
const int MAXN = 1e5+5, MAXM = 1e5+5;
int n = 0, m = 0, p = 0, a = 0, b = 0, korzen = 0, cnt = -1;
vector<int> krawedzie[MAXN];
Krawedz krawedz_in[MAXM];
int wyn[MAXM];
int ile_parent[MAXN];
int glebokosc[MAXN];
int low[MAXN];
int parent[MAXN];
bool czy_most[MAXN];
int w_jakiej_spojnej[MAXN];
int dp[MAXN];
bool visited[MAXN];
int res[MAXN];
 
inline void DFS(int v, int par)
{
	low[v] = glebokosc[v];
	parent[v] = par;
	for(auto x : krawedzie[v])
	{
		if(x == par) ++ile_parent[v];
		else if(glebokosc[x] == -1)
		{
			glebokosc[x] = glebokosc[v] + 1;
			DFS(x,v);
			low[v] = min(low[v],low[x]);
		}
		else low[v] = min(low[v],glebokosc[x]);
	}
	if(ile_parent[v] > 1) low[v] = min(low[v],glebokosc[v]-1);
	if(v != korzen and low[v] == glebokosc[v]) czy_most[v] = true;
}
 
inline void DFS2(int v)
{
	w_jakiej_spojnej[v] = cnt;
	for(auto x : krawedzie[v]) if(w_jakiej_spojnej[x] == -1) DFS2(x);
}
 
inline void DFS3(int v, int par)
{
	parent[v] = par;
	visited[v] = true;
	for(auto x : krawedzie[v])
	{
		if(visited[x] == false)
		{
			DFS3(x,v);
			dp[v] += dp[x];
		}
	}
	if(par != -1) res[v] = dp[v];
}
 
int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
 
	cin >> n >> m;
	rep(i,m)
	{
		cin >> a >> b;
		krawedz_in[i] = {a,b};
		krawedzie[a].pb(b), krawedzie[b].pb(a);
	}
 
	for(int i = 1; i <= n; ++i) glebokosc[i] = -1;
	for(int i = 1; i <= n; ++i)
	{
		if(glebokosc[i] == -1)
		{
			glebokosc[i] = 0, korzen = i;
			DFS(i,0);
		}
	}
 
	for(int i = 1; i <= n; ++i) krawedzie[i] = vector<int>();
	rep(i,m)
	{
		int a = krawedz_in[i].a, b = krawedz_in[i].b;
		if((czy_most[a] == true and parent[a] == b) or (czy_most[b] == true and parent[b] == a)) continue;
		krawedzie[a].pb(b), krawedzie[b].pb(a);
	}
 
 
	for(int i = 1; i <= n; ++i) w_jakiej_spojnej[i] = -1;
	for(int i = 1; i <= n; ++i)
	{
		if(w_jakiej_spojnej[i] == -1)
		{
			++cnt;
			DFS2(i);
		}
	}
 
	for(int i = 1; i <= n; ++i) krawedzie[i] = vector<int>();
	rep(i,m)
	{
		int a = w_jakiej_spojnej[krawedz_in[i].a], b = w_jakiej_spojnej[krawedz_in[i].b];
		if(a == b) wyn[i] = 2;
		else
		{
			krawedzie[a].pb(b), krawedzie[b].pb(a);
		}
	}
 
	cin >> p;
	rep(i,p)
	{
		cin >> a >> b;
		a = w_jakiej_spojnej[a], b = w_jakiej_spojnej[b];
		++dp[a], --dp[b];
	}
 
	for(int i = 1; i <= n; ++i) if(visited[i] == false) DFS3(i,-1);
 
	rep(i,m)
	{
		int a = w_jakiej_spojnej[krawedz_in[i].a], b = w_jakiej_spojnej[krawedz_in[i].b];
		if(a != b)
		{
			if(parent[a] == b)
			{
				if(res[a] == 0) wyn[i] = 2;
				else if(res[a] > 0) wyn[i] = 0;
				else wyn[i] = 1;
			}
			if(parent[b] == a)
			{
				if(res[b] == 0) wyn[i] = 2;
				else if(res[b] > 0) wyn[i] = 1;
				else wyn[i] = 0;
			}
		}
	}
 
	rep(i,m)
	{
		if(wyn[i] == 0) cout << 'R';
		else if (wyn[i] == 1) cout << 'L';
		else cout << 'B';
	}
	cout << '\n';
 
	return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 2648 KB Output is correct
2 Correct 1 ms 2652 KB Output is correct
3 Correct 1 ms 2908 KB Output is correct
4 Correct 1 ms 2908 KB Output is correct
5 Correct 1 ms 2908 KB Output is correct
6 Correct 1 ms 2908 KB Output is correct
7 Correct 2 ms 2908 KB Output is correct
8 Correct 1 ms 2908 KB Output is correct
9 Correct 1 ms 2832 KB Output is correct
10 Correct 2 ms 2908 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 2648 KB Output is correct
2 Correct 1 ms 2652 KB Output is correct
3 Correct 1 ms 2908 KB Output is correct
4 Correct 1 ms 2908 KB Output is correct
5 Correct 1 ms 2908 KB Output is correct
6 Correct 1 ms 2908 KB Output is correct
7 Correct 2 ms 2908 KB Output is correct
8 Correct 1 ms 2908 KB Output is correct
9 Correct 1 ms 2832 KB Output is correct
10 Correct 2 ms 2908 KB Output is correct
11 Correct 30 ms 8204 KB Output is correct
12 Correct 38 ms 9292 KB Output is correct
13 Correct 39 ms 10744 KB Output is correct
14 Correct 51 ms 11856 KB Output is correct
15 Correct 44 ms 12376 KB Output is correct
16 Correct 44 ms 11348 KB Output is correct
17 Correct 44 ms 12876 KB Output is correct
18 Correct 44 ms 11196 KB Output is correct
19 Correct 42 ms 13904 KB Output is correct
20 Correct 35 ms 9468 KB Output is correct
21 Correct 32 ms 9044 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 2648 KB Output is correct
2 Correct 1 ms 2652 KB Output is correct
3 Correct 1 ms 2908 KB Output is correct
4 Correct 1 ms 2908 KB Output is correct
5 Correct 1 ms 2908 KB Output is correct
6 Correct 1 ms 2908 KB Output is correct
7 Correct 2 ms 2908 KB Output is correct
8 Correct 1 ms 2908 KB Output is correct
9 Correct 1 ms 2832 KB Output is correct
10 Correct 2 ms 2908 KB Output is correct
11 Correct 30 ms 8204 KB Output is correct
12 Correct 38 ms 9292 KB Output is correct
13 Correct 39 ms 10744 KB Output is correct
14 Correct 51 ms 11856 KB Output is correct
15 Correct 44 ms 12376 KB Output is correct
16 Correct 44 ms 11348 KB Output is correct
17 Correct 44 ms 12876 KB Output is correct
18 Correct 44 ms 11196 KB Output is correct
19 Correct 42 ms 13904 KB Output is correct
20 Correct 35 ms 9468 KB Output is correct
21 Correct 32 ms 9044 KB Output is correct
22 Correct 86 ms 13908 KB Output is correct
23 Correct 60 ms 12368 KB Output is correct
24 Correct 95 ms 12372 KB Output is correct
25 Correct 75 ms 16964 KB Output is correct
26 Correct 93 ms 13648 KB Output is correct
27 Correct 80 ms 12628 KB Output is correct
28 Correct 22 ms 5468 KB Output is correct
29 Correct 41 ms 10032 KB Output is correct
30 Correct 52 ms 10320 KB Output is correct
31 Correct 47 ms 10440 KB Output is correct
32 Correct 51 ms 12884 KB Output is correct