답안 #211119

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
211119 2020-03-19T09:03:47 Z arnold518 One-Way Streets (CEOI17_oneway) C++14
100 / 100
140 ms 19832 KB
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

const int MAXN = 1e5;

int N, M, P;
pii E[MAXN+10];
vector<pii> adj[MAXN+10], adj2[MAXN+10];
int ans[MAXN+10];
char S[5]="!BRL";

int dfn[MAXN+10], low[MAXN+10], cnt;

void dfs(int now, int bef)
{
	dfn[now]=low[now]=++cnt;
	for(auto nxt : adj[now])
	{
		if(nxt.second==bef) continue;
		if(dfn[nxt.first]==0)
		{
			dfs(nxt.first, nxt.second);
			low[now]=min(low[now], low[nxt.first]);
			if(low[nxt.first]<=dfn[now]) ans[nxt.second]=1;
		}
		else
		{
			ans[nxt.second]=1;
			low[now]=min(low[now], dfn[nxt.first]);
		}
	}
}

int bcc[MAXN+10], bcnt;
void color(int now, int col)
{
	bcc[now]=col;
	for(auto nxt : adj[now])
	{
		if(bcc[nxt.first]) continue;
		if(ans[nxt.second]) color(nxt.first, col);
		else
		{
			++bcnt;
			adj2[col].push_back({bcnt, nxt.second});
			//printf("!%d %d!\n", col, bcnt);
			color(nxt.first, bcnt);
		}
	}
}

int dp[MAXN+10];
void dfs2(int now)
{
	for(auto nxt : adj2[now])
	{
		dfs2(nxt.first);
		if(dp[nxt.first]>0)
		{
			int u=E[nxt.second].first;
			if(bcc[u]==nxt.first) ans[nxt.second]=2;
			else ans[nxt.second]=3;
		}
		else if(dp[nxt.first]<0)
		{
			int u=E[nxt.second].first;
			if(bcc[u]==nxt.first) ans[nxt.second]=3;
			else ans[nxt.second]=2;
		}
		else ans[nxt.second]=1;
		dp[now]+=dp[nxt.first];
	}
}

int main()
{
	int i, j;

	scanf("%d%d", &N, &M);
	for(i=1; i<=M; i++)
	{
		scanf("%d%d", &E[i].first, &E[i].second);
		adj[E[i].first].push_back({E[i].second, i});
		adj[E[i].second].push_back({E[i].first, i});
	}

	vector<int> root;
	for(i=1; i<=N; i++)
	{
		if(dfn[i]) continue;
		dfs(i, 0);
		++bcnt; root.push_back(bcnt);
		color(i, bcnt);
	}

	scanf("%d", &P);
	while(P--)
	{
		int u, v;
		scanf("%d%d", &u, &v);
		if(bcc[u]==bcc[v]) continue;
		int bu=bcc[u], bv=bcc[v];
		dp[bu]++; dp[bv]--;
	}

	for(auto it : root) dfs2(it);

	//for(i=1; i<=N; i++) printf("%d ", bcc[i]); printf("\n");

	for(i=1; i<=M; i++) printf("%c", S[ans[i]]);
	printf("\n");
} 

Compilation message

oneway.cpp: In function 'int main()':
oneway.cpp:81:9: warning: unused variable 'j' [-Wunused-variable]
  int i, j;
         ^
oneway.cpp:83:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d%d", &N, &M);
  ~~~~~^~~~~~~~~~~~~~~~
oneway.cpp:86:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d%d", &E[i].first, &E[i].second);
   ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
oneway.cpp:100:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d", &P);
  ~~~~~^~~~~~~~~~
oneway.cpp:104:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d%d", &u, &v);
   ~~~~~^~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 4992 KB Output is correct
2 Correct 7 ms 4864 KB Output is correct
3 Correct 8 ms 5120 KB Output is correct
4 Correct 8 ms 5120 KB Output is correct
5 Correct 8 ms 5120 KB Output is correct
6 Correct 8 ms 5120 KB Output is correct
7 Correct 8 ms 5120 KB Output is correct
8 Correct 8 ms 5120 KB Output is correct
9 Correct 8 ms 5120 KB Output is correct
10 Correct 7 ms 5120 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 4992 KB Output is correct
2 Correct 7 ms 4864 KB Output is correct
3 Correct 8 ms 5120 KB Output is correct
4 Correct 8 ms 5120 KB Output is correct
5 Correct 8 ms 5120 KB Output is correct
6 Correct 8 ms 5120 KB Output is correct
7 Correct 8 ms 5120 KB Output is correct
8 Correct 8 ms 5120 KB Output is correct
9 Correct 8 ms 5120 KB Output is correct
10 Correct 7 ms 5120 KB Output is correct
11 Correct 65 ms 11256 KB Output is correct
12 Correct 69 ms 12152 KB Output is correct
13 Correct 90 ms 13048 KB Output is correct
14 Correct 98 ms 14072 KB Output is correct
15 Correct 95 ms 14196 KB Output is correct
16 Correct 101 ms 14712 KB Output is correct
17 Correct 82 ms 16120 KB Output is correct
18 Correct 107 ms 14584 KB Output is correct
19 Correct 103 ms 17156 KB Output is correct
20 Correct 70 ms 11896 KB Output is correct
21 Correct 66 ms 11640 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 4992 KB Output is correct
2 Correct 7 ms 4864 KB Output is correct
3 Correct 8 ms 5120 KB Output is correct
4 Correct 8 ms 5120 KB Output is correct
5 Correct 8 ms 5120 KB Output is correct
6 Correct 8 ms 5120 KB Output is correct
7 Correct 8 ms 5120 KB Output is correct
8 Correct 8 ms 5120 KB Output is correct
9 Correct 8 ms 5120 KB Output is correct
10 Correct 7 ms 5120 KB Output is correct
11 Correct 65 ms 11256 KB Output is correct
12 Correct 69 ms 12152 KB Output is correct
13 Correct 90 ms 13048 KB Output is correct
14 Correct 98 ms 14072 KB Output is correct
15 Correct 95 ms 14196 KB Output is correct
16 Correct 101 ms 14712 KB Output is correct
17 Correct 82 ms 16120 KB Output is correct
18 Correct 107 ms 14584 KB Output is correct
19 Correct 103 ms 17156 KB Output is correct
20 Correct 70 ms 11896 KB Output is correct
21 Correct 66 ms 11640 KB Output is correct
22 Correct 124 ms 17272 KB Output is correct
23 Correct 125 ms 16120 KB Output is correct
24 Correct 140 ms 15736 KB Output is correct
25 Correct 127 ms 19832 KB Output is correct
26 Correct 116 ms 16888 KB Output is correct
27 Correct 120 ms 15992 KB Output is correct
28 Correct 58 ms 9592 KB Output is correct
29 Correct 95 ms 12664 KB Output is correct
30 Correct 92 ms 12792 KB Output is correct
31 Correct 99 ms 12920 KB Output is correct
32 Correct 94 ms 15568 KB Output is correct