QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#559497#8835. GoodmanAmanicus#TL 234ms11376kbC++14759b2024-09-11 22:32:382024-09-11 22:32:38

Judging History

你现在查看的是最新测评结果

  • [2024-09-11 22:32:38]
  • 评测
  • 测评结果:TL
  • 用时:234ms
  • 内存:11376kb
  • [2024-09-11 22:32:38]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define llt __int128_t
#define IOS ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
const int N = 1e2+10;
const int M = 1e6 + 7;
const int MAX = 0x3f3f3f3f;
const ll maxn = 1e18;
ll h,s1,vv,u,mi,mx,fz,fm,ans,item,f;
ll m,n,x,y,x2,y2,z,z2,d,gcd,l,r,T,p,cnt;
ll sum;
ll c[M];
ll a[N];
vector<ll>b;
void solve() {
	memset(c,0,sizeof(c));
	b.clear();
	cin>>n;
	for(ll i=1;i<=n;i++){
		cin>>a[i];
	}
	for(ll i=1;i<=n;i++){
		if(c[i]){
			continue;
		}
		ll k=i;
		while(!c[k]){
			b.push_back(k);
			c[k]=1;
			k=a[k];
		}
	}
	for(auto it:b){
		cout<<it<<" ";
	}
	cout<<'\n';
}
int main() {
	IOS;
	T=1;
	cin>>T;
	while(T--) {
		solve();
	}
	return 0;
}

详细

Test #1:

score: 100
Accepted
time: 2ms
memory: 11344kb

input:

2
4
1 2 3 4
6
6 5 4 3 2 1

output:

1 2 3 4 
1 6 2 5 3 4 

result:

ok Correct (2 test cases)

Test #2:

score: 0
Accepted
time: 234ms
memory: 11376kb

input:

873
6
1 5 2 4 6 3
6
5 1 6 4 3 2
4
1 4 3 2
6
2 1 6 5 4 3
6
4 5 1 3 6 2
6
6 2 1 5 4 3
5
1 5 4 3 2
6
1 2 6 3 5 4
4
2 1 3 4
6
1 6 4 2 3 5
6
6 1 3 5 2 4
6
2 1 4 5 3 6
6
3 4 1 5 2 6
6
4 1 5 2 6 3
6
5 2 1 4 6 3
6
4 1 6 2 3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