답안 #303940

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
303940 2020-09-20T19:48:50 Z peuch One-Way Streets (CEOI17_oneway) C++17
0 / 100
6 ms 9728 KB
#include<bits/stdc++.h>
using namespace std;

const int MAXN = 100010;

int n, m, p;
int low[MAXN], pre[MAXN];
int cnt;
int bridge[MAXN];
pair<int, int> edge[MAXN];
int rep[MAXN], tam[MAXN];
int auxSum[MAXN];
int ans[MAXN];


vector<int> ar[MAXN], id[MAXN];
vector<int> tree[MAXN], treeID[MAXN];

void dfs(int cur, int pai);
void uni(int a, int b);
int find(int a);
void endCalc(int cur, int pai);

int main(){
	scanf("%d %d", &n, &m);
	for(int i = 1; i <= n; i++) rep[i] = i, tam[i] = 1;
	for(int i = 1; i <= m; i++){
		int a, b;
		scanf("%d %d", &a, &b);
		ar[a].push_back(b);
		ar[b].push_back(a);
		id[a].push_back(i);
		id[b].push_back(i);
		edge[i] = make_pair(a, b);
	}
	dfs(1, 0);
	for(int i = 1; i <= m; i++){
		if(bridge[i]) continue;
		uni(edge[i].first, edge[i].second);
	}
	for(int i = 1; i <= m; i++){
		if(!bridge[i]) continue;
		int a = edge[i].first;
		int b = edge[i].second;
		a = find(a);
		b = find(b);
		tree[a].push_back(b);
		tree[b].push_back(a);
		treeID[a].push_back(i);
		treeID[b].push_back(i);
	}
	scanf("%d", &p);
	for(int i = 1; i <= p; i++){
		int a, b;
		scanf("%d %d", &a, &b);
		a = find(a);
		b = find(b);
		auxSum[a]++;
		auxSum[b]--;
	}
	endCalc(find(1), 0);
	for(int i = 1; i <= m; i++){
		if(ans[i] == 1) printf("R");
		else if(ans[i] == -1) printf("L");
		else printf("B");
	}
	return 0;
}

void dfs(int cur, int pai){
	pre[cur] = low[cur] = ++cnt;
	for(int i = 0; i < ar[cur].size(); i++){
		int viz = ar[cur][i];
		if(id[cur][i] == pai) continue;
		if(pre[viz] != 0) low[cur] = min(low[cur], pre[viz]);
		else{
			dfs(viz, id[cur][i]);
			if(low[viz] > pre[cur]) bridge[id[cur][i]] = 1;
			low[cur] = min(low[cur], low[viz]);
		}
	}
}

void uni(int a, int b){
	a = find(a);
	b = find(b);
	if(a == b) return;
	if(tam[a] > tam[b])
		tam[a] += tam[b], rep[b] = a;	
	else
		tam[b] += tam[a], rep[a] = b;	
}

int find(int a){
	if(rep[a] == a) return a;
	return rep[a] = find(rep[a]);
}

void endCalc(int cur, int pai){
	for(int i = 0; i < tree[cur].size(); i++){
		int viz = tree[cur][i];
		int eID = treeID[cur][i];
		if(viz == pai) continue;
		endCalc(viz, cur);
		if(auxSum[viz] < 0){
			if(find(edge[eID].first) == cur) ans[eID] = 1;
			else ans[eID] = -1;
		}
		else if(auxSum[viz] > 0){
			if(find(edge[eID].first) == cur) ans[eID] = -1;
			else ans[eID] = 1;
		}
		auxSum[cur] += auxSum[viz];
	}
}

Compilation message

oneway.cpp: In function 'void dfs(int, int)':
oneway.cpp:72:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   72 |  for(int i = 0; i < ar[cur].size(); i++){
      |                 ~~^~~~~~~~~~~~~~~~
oneway.cpp: In function 'void endCalc(int, int)':
oneway.cpp:100:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  100 |  for(int i = 0; i < tree[cur].size(); i++){
      |                 ~~^~~~~~~~~~~~~~~~~~
oneway.cpp: In function 'int main()':
oneway.cpp:25:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   25 |  scanf("%d %d", &n, &m);
      |  ~~~~~^~~~~~~~~~~~~~~~~
oneway.cpp:29:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   29 |   scanf("%d %d", &a, &b);
      |   ~~~~~^~~~~~~~~~~~~~~~~
oneway.cpp:52:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   52 |  scanf("%d", &p);
      |  ~~~~~^~~~~~~~~~
oneway.cpp:55:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   55 |   scanf("%d %d", &a, &b);
      |   ~~~~~^~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Incorrect 6 ms 9728 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 6 ms 9728 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 6 ms 9728 KB Output isn't correct
2 Halted 0 ms 0 KB -