結果

問題 No.2301 Namorientation
ユーザー kabipoyokabipoyo
提出日時 2023-05-13 09:51:10
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 2,396 bytes
コンパイル時間 5,334 ms
コンパイル使用メモリ 282,560 KB
実行使用メモリ 34,336 KB
最終ジャッジ日時 2024-05-06 18:46:47
合計ジャッジ時間 25,722 ms
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,812 KB
testcase_01 WA -
testcase_02 WA -
testcase_03 AC 2 ms
6,940 KB
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 AC 2 ms
6,944 KB
testcase_08 AC 2 ms
6,944 KB
testcase_09 AC 3 ms
6,940 KB
testcase_10 AC 2 ms
6,940 KB
testcase_11 AC 2 ms
6,940 KB
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 AC 415 ms
19,004 KB
testcase_23 AC 408 ms
18,780 KB
testcase_24 AC 335 ms
16,256 KB
testcase_25 AC 368 ms
27,264 KB
testcase_26 AC 483 ms
34,336 KB
testcase_27 WA -
testcase_28 WA -
testcase_29 WA -
testcase_30 WA -
testcase_31 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#include <atcoder/all>
using namespace std;
using namespace atcoder;
typedef int64_t lint;
#define rep(i, n) for(int i=0; i<n; i++)
#define repx(i, l, n) for(int i=l; i<n; i++)
#define all(v) v.begin(), v.end()
#define show(x) cout << #x << ": " << x << endl;
#define list(x) cout << #x << ": " << x << "  ";
#define pb push_back
using vi = vector<lint>;
using vvi = vector<vector<lint>>;
template<class T> inline void vin(vector<T>& v) { rep(i, v.size()) cin >> v.at(i); }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
template<class T> inline void drop(T x) { cout << x << endl; exit(0); }
template<class T> void vout(vector<T> v) { rep(i, v.size()) { cout << v.at(i) << ' '; } cout << endl; }
constexpr lint LINF = LLONG_MAX/2;
vector<vector<lint>> G;
vi l, r;
void make_graph(lint N, lint M) {
	G.resize(N);
	lint x, y;
	rep(i, M) {
		cin >> x >> y;
		x--, y--;
		l.pb(x), r.pb(y);
		G[x].push_back(y);
		G[y].push_back(x);
	}
}

vi topo_sort() {
	vi res;
	lint N = G.size();
	vi v(N);
	rep(i, N) { for (auto e : G[i]) v[e]++; }
	queue<int> Q;
	rep(i, N) { if (v[i] == 1) Q.push(i); }
	while (!Q.empty()) {
		int x = Q.front(); Q.pop();
		res.push_back(x);
		for (auto e : G[x]) {
			v[e]--;
			if (v[e] == 1) Q.push(e);
		}
	}
	return res;
}

using pint = pair<lint, lint>;
using vp = vector<pint>;
vector<lint> dist;
void dfs(int root) {
	lint x, y, z, N = G.size();
	dist.resize(N, -1);
	stack<pint> Q;
	Q.push({root, root}), dist[root] = -1;
	while (!Q.empty()) {
		tie(x, z) = Q.top(); Q.pop();
		if (dist[x] != -1) continue;
		dist[x] = dist[z]+1;
		rep(i, G[x].size()) {
			y = G[x][i];
			if (dist[y] == -1) Q.push({y, x});
		}
	}
}

int main() {
	lint N;
	cin >> N;
	make_graph(N, N);

	lint a=0, b=0, c=0, x, y, z;
	vi v = topo_sort();
	set<lint> s;
	rep(i, v.size()) s.insert(v[i]);
	rep(i, N) {
		if (!s.count(i)) {
			dfs(i);
			break;
		}
	}
	rep(i, N) {
		if (s.count(l[i])) {
			cout << "->" << endl;
		} else if (s.count(r[i])) {
			cout << "<-" << endl;
		} else {
			if (dist[l[i]]+1 == dist[r[i]]) {
				cout << "->" << endl;
			} else if (dist[l[i]] == dist[r[i]]+1) {
				cout << "<-" << endl;
			} else if (dist[l[i]] == 0) {
				cout << "<-" << endl;
			} else {
				cout << "->" << endl;
			}
		}
	}
}
0