Submission #73301040


Source Code Expand

#include <bits/stdc++.h>
#define int long long
using namespace std;

const int N = 5e5 + 5;
int n,a[N],fa[N];

void init()
{
	for(int i = 1;i <= n;i++) fa[i] = i;
}

int getfa(int x)
{
	return (fa[x] == x ? x : fa[x] = getfa(fa[x]));
}

signed main()
{
	cin >> n;
	init();
	for(int i = 1;i <= n;i++)
	{
		cin >> a[i];
		int u = getfa(i),v = getfa(a[i]);
		if(u == v) continue;
		fa[u] = v;
	}
	for(int i = 1;i <= n;i++) cout << getfa(i) << ' ';
	return 0; 
}

Submission Info

Submission Time
Task C - Sugoroku Destination
User world_kiana
Language C++23 (GCC 15.2.0)
Score 300
Code Size 488 Byte
Status AC
Exec Time 123 ms
Memory 17716 KiB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 300 / 300
Status
AC × 3
AC × 18
Set Name Test Cases
Sample 00_sample_00.txt, 00_sample_01.txt, 00_sample_02.txt
All 00_sample_00.txt, 00_sample_01.txt, 00_sample_02.txt, 01_random_03.txt, 01_random_04.txt, 01_random_05.txt, 01_random_06.txt, 01_random_07.txt, 01_random_08.txt, 01_random_09.txt, 01_random_10.txt, 01_random_11.txt, 01_random_12.txt, 01_random_13.txt, 01_random_14.txt, 01_random_15.txt, 01_random_16.txt, 01_random_17.txt
Case Name Status Exec Time Memory
00_sample_00.txt AC 1 ms 3352 KiB
00_sample_01.txt AC 1 ms 3468 KiB
00_sample_02.txt AC 1 ms 3504 KiB
01_random_03.txt AC 121 ms 11756 KiB
01_random_04.txt AC 122 ms 11720 KiB
01_random_05.txt AC 123 ms 11820 KiB
01_random_06.txt AC 123 ms 11812 KiB
01_random_07.txt AC 121 ms 11728 KiB
01_random_08.txt AC 120 ms 11772 KiB
01_random_09.txt AC 120 ms 11732 KiB
01_random_10.txt AC 119 ms 11784 KiB
01_random_11.txt AC 42 ms 6288 KiB
01_random_12.txt AC 35 ms 5960 KiB
01_random_13.txt AC 106 ms 10500 KiB
01_random_14.txt AC 7 ms 4076 KiB
01_random_15.txt AC 119 ms 11756 KiB
01_random_16.txt AC 1 ms 3480 KiB
01_random_17.txt AC 110 ms 17716 KiB