結果

問題 No.2301 Namorientation
ユーザー shobonvipshobonvip
提出日時 2023-05-12 21:53:19
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,835 bytes
コンパイル時間 4,675 ms
コンパイル使用メモリ 268,064 KB
実行使用メモリ 21,388 KB
最終ジャッジ日時 2024-05-06 11:41:50
合計ジャッジ時間 22,492 ms
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 WA -
testcase_02 WA -
testcase_03 AC 2 ms
5,376 KB
testcase_04 WA -
testcase_05 AC 2 ms
5,376 KB
testcase_06 WA -
testcase_07 AC 2 ms
5,376 KB
testcase_08 AC 2 ms
5,376 KB
testcase_09 AC 2 ms
5,376 KB
testcase_10 AC 2 ms
5,376 KB
testcase_11 AC 2 ms
5,376 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 410 ms
19,468 KB
testcase_23 AC 410 ms
19,100 KB
testcase_24 AC 339 ms
16,680 KB
testcase_25 AC 291 ms
17,600 KB
testcase_26 AC 376 ms
21,388 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 modint998244353 mint;
typedef long long ll;

int main(){
	int n; cin >> n;
	vector<vector<pair<int,int>>> ikeru;
	ikeru.resize(n);
	vector<int> deg(n);
	vector<int> x(n), y(n);
	for (int i=0; i<n; i++){
		int a, b;
		cin >> a >> b;
		a--; b--;
		deg[a]++;
		deg[b]++;
		x[i] = a;
		y[i] = b;
		ikeru[a].push_back(pair(b,i));
		ikeru[b].push_back(pair(a,i));
	}
	vector<int> mada;
	vector<bool> isnamori(n, true);
	vector<int> comefrom(n,-1);
	vector<int> kousha(n,-1);
	for (int i=0; i<n; i++){
		if (deg[i] == 1){
			mada.push_back(i);
		}
	}
	while (!mada.empty()){
		int i = mada.back();
		mada.pop_back();
		isnamori[i] = false;
		for (auto [j,c]: ikeru[i]){
			deg[j]--;
			if (deg[j] <= 0){
				mada.push_back(j);
				comefrom[j] = i;
				kousha[c] = i;
			}
		}
	}

	vector<bool> tansaku(n);
	for (int i=0; i<n; i++){
		if (!isnamori[i]){
			tansaku[i] = true;
		}
	}

	for (int i=0; i<n; i++){
		if (isnamori[i]){
			mada.push_back(i);
			break;
		}
	}

	vector<int> arr;
	while(!mada.empty()){
		int i = mada.back();
		mada.pop_back();
		if (tansaku[i]) continue;
		arr.push_back(i);
		tansaku[i] = true;
		for (auto [j,c]: ikeru[i]){
			if (!tansaku[j]){
				mada.push_back(j);
			}
		}
	}

	int m = arr.size();
	arr.push_back(arr[0]);
	
	for (int i=0; i<m; i++){
		comefrom[arr[i+1]] = arr[i];
	}

	for (int i=0; i<n; i++){
		if (isnamori[x[i]] && isnamori[y[i]]){
			if (comefrom[y[i]] == x[i]){
				cout << "->" << endl;
			}else{
				cout << "<-" << endl;
			}
		}else if (isnamori[x[i]] && !isnamori[y[i]]){
			cout << "<-" << endl;
		}else if (!isnamori[x[i]] && isnamori[y[i]]){
			cout << "->" << endl;
		}else{
			if (kousha[i] == y[i]){
				cout << "->" << endl;
			}else{
				cout << "<-" << endl;
			}
		}
	}

}
0