結果

問題 No.2301 Namorientation
ユーザー kabipoyokabipoyo
提出日時 2023-05-13 09:51:10
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
WA  
実行時間 -
コード長 2,396 bytes
コンパイル時間 4,723 ms
コンパイル使用メモリ 270,532 KB
最終ジャッジ日時 2025-02-12 23:55:23
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1 WA * 1
other AC * 11 WA * 19
権限があれば一括ダウンロードができます

ソースコード

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