結果

問題 No.2301 Namorientation
ユーザー kotatsugamekotatsugame
提出日時 2023-05-12 21:36:16
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 113 ms / 3,000 ms
コード長 1,137 bytes
コンパイル時間 796 ms
コンパイル使用メモリ 73,728 KB
実行使用メモリ 22,264 KB
最終ジャッジ日時 2024-05-06 11:18:07
合計ジャッジ時間 9,660 ms
ジャッジサーバーID
(参考情報)
judge3 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 5 ms
9,472 KB
testcase_01 AC 6 ms
9,472 KB
testcase_02 AC 5 ms
9,472 KB
testcase_03 AC 6 ms
9,472 KB
testcase_04 AC 6 ms
9,472 KB
testcase_05 AC 7 ms
9,472 KB
testcase_06 AC 6 ms
9,600 KB
testcase_07 AC 6 ms
9,472 KB
testcase_08 AC 7 ms
9,600 KB
testcase_09 AC 6 ms
9,600 KB
testcase_10 AC 6 ms
9,600 KB
testcase_11 AC 6 ms
9,472 KB
testcase_12 AC 59 ms
16,256 KB
testcase_13 AC 57 ms
15,760 KB
testcase_14 AC 109 ms
21,132 KB
testcase_15 AC 70 ms
17,552 KB
testcase_16 AC 93 ms
19,560 KB
testcase_17 AC 67 ms
16,512 KB
testcase_18 AC 100 ms
19,856 KB
testcase_19 AC 48 ms
15,392 KB
testcase_20 AC 94 ms
19,632 KB
testcase_21 AC 67 ms
17,080 KB
testcase_22 AC 68 ms
20,048 KB
testcase_23 AC 64 ms
19,768 KB
testcase_24 AC 56 ms
18,376 KB
testcase_25 AC 44 ms
19,580 KB
testcase_26 AC 59 ms
22,264 KB
testcase_27 AC 105 ms
21,056 KB
testcase_28 AC 108 ms
21,248 KB
testcase_29 AC 113 ms
21,180 KB
testcase_30 AC 112 ms
21,180 KB
testcase_31 AC 113 ms
21,180 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<iostream>
#include<vector>
using namespace std;
int deg[2<<17];
int N,A[2<<17],B[2<<17];
int from[2<<17];
vector<pair<int,int> >G[2<<17];
bool vis[2<<17];
int main()
{
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	cin>>N;
	for(int i=0;i<N;i++)
	{
		cin>>A[i]>>B[i];
		A[i]--,B[i]--;
		deg[A[i]]++;
		deg[B[i]]++;
		G[A[i]].push_back(make_pair(B[i],i));
		G[B[i]].push_back(make_pair(A[i],i));
		from[i]=-1;
	}
	vector<int>Q;
	for(int i=0;i<N;i++)if(deg[i]==1)
	{
		Q.push_back(i);
		vis[i]=true;
	}
	for(int i=0;i<Q.size();i++)
	{
		int u=Q[i];
		for(pair<int,int>e:G[u])if(!vis[e.first])
		{
			from[e.second]=u;
			if(--deg[e.first]==1)
			{
				Q.push_back(e.first);
				vis[e.first]=true;
			}
		}
	}
	Q.clear();
	int u=0;
	while(vis[u])u++;
	Q.push_back(u);
	int st=u;
	for(int i=0;i<Q.size();i++)
	{
		int u=Q[i];
		vis[u]=true;
		for(pair<int,int>e:G[u])if(!vis[e.first])
		{
			from[e.second]=u;
			Q.push_back(e.first);
			break;
		}
	}
	for(int i=0;i<N;i++)
	{
		if(from[i]!=-1)
		{
			if(from[i]==A[i])cout<<"->\n";
			else cout<<"<-\n";
		}
		else
		{
			if(st==A[i])cout<<"<-\n";
			else cout<<"->\n";
		}
	}
}
0