Submission #60143845


Source Code Expand

#include<bits/stdc++.h>
#include"atcoder/all"
using namespace std;
using namespace atcoder;
#define rep(i,n) for(int i=0;i<(n);i++)
#define all(a) a.begin(),a.end()
typedef long long ll;
typedef vector<ll> vi;
typedef pair<ll,ll> P;
const ll mod=998244353;
const ll inf=1ll<<61;
typedef modint998244353 mi;

int a[100005],b[100005];

vector<int>G[100005];
bool used[100005];

int main(){
	int n;cin>>n;
	queue<int>Q;
	rep(i,n){
		cin>>a[i]>>b[i];
		a[i]--;
		b[i]--;
		G[a[i]].push_back(i);
		G[b[i]].push_back(i);
		if(a[i]==i||b[i]==i){
			Q.push(i);
			used[i]=true;
		}
	}
	vector<int>ans;
	while(Q.size()){
		int v=Q.front();
		Q.pop();
		ans.push_back(v);
		for(auto &e:G[v]){
			if(!used[e]){
				used[e]=true;
				Q.push(e);
			}
		}
	}
	if(ans.size()==n){
		reverse(all(ans));
		rep(i,n)cout<<ans[i]+1<<endl;
	}
	else{
		cout<<-1<<endl;
	}
}

Submission Info

Submission Time
Task 062 - Paint All(★6)
User Rho17
Language C++ 20 (gcc 12.2)
Score 6
Code Size 901 Byte
Status AC
Exec Time 163 ms
Memory 10280 KiB

Compile Error

Main.cpp: In function ‘int main()’:
Main.cpp:45:22: warning: comparison of integer expressions of different signedness: ‘std::vector<int>::size_type’ {aka ‘long unsigned int’} and ‘int’ [-Wsign-compare]
   45 |         if(ans.size()==n){
      |            ~~~~~~~~~~^~~

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 6 / 6
Status
AC × 5
AC × 50
Set Name Test Cases
Sample sample_01.txt, sample_02.txt, sample_03.txt, sample_04.txt, sample_05.txt
All 01_random_yes_01.txt, 01_random_yes_02.txt, 01_random_yes_03.txt, 01_random_yes_04.txt, 01_random_yes_05.txt, 01_random_yes_06.txt, 01_random_yes_07.txt, 01_random_yes_08.txt, 01_random_yes_09.txt, 01_random_yes_10.txt, 02_random_no_01.txt, 02_random_no_02.txt, 02_random_no_03.txt, 02_random_no_04.txt, 02_random_no_05.txt, 02_random_no_06.txt, 02_random_no_07.txt, 02_random_no_08.txt, 02_random_no_09.txt, 02_random_no_10.txt, 03_large_yes_01.txt, 03_large_yes_02.txt, 03_large_yes_03.txt, 03_large_yes_04.txt, 03_large_yes_05.txt, 04_large_no_01.txt, 04_large_no_02.txt, 04_large_no_03.txt, 04_large_no_04.txt, 04_large_no_05.txt, 05_small_yes_01.txt, 05_small_yes_02.txt, 05_small_yes_03.txt, 05_small_yes_04.txt, 05_small_yes_05.txt, 06_small_no_01.txt, 06_small_no_02.txt, 06_small_no_03.txt, 06_small_no_04.txt, 06_small_no_05.txt, 07_linear_yes_01.txt, 07_linear_yes_02.txt, 07_linear_yes_03.txt, 07_linear_yes_04.txt, 07_linear_yes_05.txt, sample_01.txt, sample_02.txt, sample_03.txt, sample_04.txt, sample_05.txt
Case Name Status Exec Time Memory
01_random_yes_01.txt AC 43 ms 5208 KiB
01_random_yes_02.txt AC 107 ms 7364 KiB
01_random_yes_03.txt AC 44 ms 5548 KiB
01_random_yes_04.txt AC 72 ms 6440 KiB
01_random_yes_05.txt AC 97 ms 7640 KiB
01_random_yes_06.txt AC 154 ms 9764 KiB
01_random_yes_07.txt AC 34 ms 4984 KiB
01_random_yes_08.txt AC 84 ms 6980 KiB
01_random_yes_09.txt AC 64 ms 6140 KiB
01_random_yes_10.txt AC 39 ms 5256 KiB
02_random_no_01.txt AC 34 ms 7324 KiB
02_random_no_02.txt AC 39 ms 7884 KiB
02_random_no_03.txt AC 9 ms 4600 KiB
02_random_no_04.txt AC 44 ms 7960 KiB
02_random_no_05.txt AC 8 ms 4644 KiB
02_random_no_06.txt AC 46 ms 8420 KiB
02_random_no_07.txt AC 35 ms 7520 KiB
02_random_no_08.txt AC 20 ms 5908 KiB
02_random_no_09.txt AC 53 ms 9388 KiB
02_random_no_10.txt AC 30 ms 7068 KiB
03_large_yes_01.txt AC 142 ms 9576 KiB
03_large_yes_02.txt AC 153 ms 9900 KiB
03_large_yes_03.txt AC 158 ms 9708 KiB
03_large_yes_04.txt AC 147 ms 9772 KiB
03_large_yes_05.txt AC 152 ms 9840 KiB
04_large_no_01.txt AC 49 ms 9768 KiB
04_large_no_02.txt AC 51 ms 9392 KiB
04_large_no_03.txt AC 54 ms 9316 KiB
04_large_no_04.txt AC 52 ms 9340 KiB
04_large_no_05.txt AC 58 ms 9708 KiB
05_small_yes_01.txt AC 2 ms 3652 KiB
05_small_yes_02.txt AC 2 ms 3460 KiB
05_small_yes_03.txt AC 2 ms 3540 KiB
05_small_yes_04.txt AC 2 ms 3628 KiB
05_small_yes_05.txt AC 2 ms 3540 KiB
06_small_no_01.txt AC 2 ms 3476 KiB
06_small_no_02.txt AC 2 ms 3512 KiB
06_small_no_03.txt AC 2 ms 3464 KiB
06_small_no_04.txt AC 1 ms 3492 KiB
06_small_no_05.txt AC 2 ms 3496 KiB
07_linear_yes_01.txt AC 162 ms 10280 KiB
07_linear_yes_02.txt AC 163 ms 10216 KiB
07_linear_yes_03.txt AC 151 ms 9832 KiB
07_linear_yes_04.txt AC 151 ms 9764 KiB
07_linear_yes_05.txt AC 162 ms 10016 KiB
sample_01.txt AC 2 ms 3496 KiB
sample_02.txt AC 1 ms 3540 KiB
sample_03.txt AC 2 ms 3576 KiB
sample_04.txt AC 2 ms 3556 KiB
sample_05.txt AC 2 ms 3428 KiB