제출 #1263689

#제출 시각아이디문제언어결과실행 시간메모리
1263689shiori_chanOne-Way Streets (CEOI17_oneway)C++17
100 / 100
62 ms23364 KiB
#include <algorithm>
#include <iostream>
#include <vector>

using namespace std;

const int N = 100000;
const int M = 100000;
const int K = 100000;

vector<int> eh[N], ez[N];
int ii[M], jj[M], uu[K], vv[K], ta_[N], ta[N], tb[N];
char cc[M + 1];

void dfs(int i) {
	if (ta_[i])
		return;
	static int t = 0;
	ta_[i] = ++t;
	for (int h : eh[i])
		dfs(i ^ ii[h] ^ jj[h]);
}

pair<int, pair<int, int>> dfs(int h_, int i) {
	static int t = 0;
	ta[i] = ++t;
	int p_ = i, zl_ = -1, zr_ = -1;
	for (int h : eh[i])
		if (h != h_) {
			int j = i ^ ii[h] ^ jj[h];
			if (!ta[j]) {
				auto o = dfs(h, j); int p = o.first, zl = o.second.first, zr = o.second.second;
				if (ta[p] < ta[j] || zl == -1 || ta[j] <= min(ta_[uu[zl]], ta_[vv[zl]]) && max(ta_[uu[zr]], ta_[vv[zr]]) <= tb[j])
					cc[h] = 'B';
				else
					cc[h] = ii[h] == ((min(ta_[uu[zl]], ta_[vv[zl]]) < ta[j] ? ta_[uu[zl]] < ta[j] : ta_[uu[zr]] > tb[j]) ? i : j) ? 'R' : 'L';
				if (ta[p_] > ta[p])
					p_ = p;
				if (zl != -1) {
					if (zl_ == -1 || min(ta_[uu[zl_]], ta_[vv[zl_]]) > min(ta_[uu[zl]], ta_[vv[zl]]))
						zl_ = zl;
					if (zr_ == -1 || max(ta_[uu[zr_]], ta_[vv[zr_]]) < max(ta_[uu[zr]], ta_[vv[zr]]))
						zr_ = zr;
				}
			} else {
				cc[h] = 'B';
				if (ta[p_] > ta[j])
					p_ = j;
			}
		}
	tb[i] = t;
	for (int z : ez[i]) {
		if (zl_ == -1 || min(ta_[uu[zl_]], ta_[vv[zl_]]) > min(ta_[uu[z]], ta_[vv[z]]))
			zl_ = z;
		if (zr_ == -1 || max(ta_[uu[zr_]], ta_[vv[zr_]]) < max(ta_[uu[z]], ta_[vv[z]]))
			zr_ = z;
	}
	return { p_, { zl_, zr_ } };
}

int main() {
	ios_base::sync_with_stdio(false), cin.tie(NULL);
	#define task "task"
	if(fopen(task".inp", "r")) {
		freopen(task".inp", "r", stdin);
		freopen(task".ans", "w", stdout);
	}
	int n, m; cin >> n >> m;
	for (int h = 0; h < m; h++) {
		int i, j; cin >> i >> j, i--, j--;
		eh[ii[h] = i].push_back(h);
		eh[jj[h] = j].push_back(h);
	}
	int k; cin >> k;
	for (int z = 0; z < k; z++) {
		int u, v; cin >> u >> v, u--, v--;
		ez[uu[z] = u].push_back(z);
		ez[vv[z] = v].push_back(z);
	}
	for (int i = 0; i < n; i++)
		if (!ta[i])
			dfs(i), dfs(-1, i);
	cc[m] = '\0';
	cout << cc << '\n';
	return 0;
}

컴파일 시 표준 에러 (stderr) 메시지

oneway.cpp: In function 'int main()':
oneway.cpp:65:24: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   65 |                 freopen(task".inp", "r", stdin);
      |                 ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
oneway.cpp:66:24: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   66 |                 freopen(task".ans", "w", stdout);
      |                 ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...