QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#602286 | #8835. Goodman | szcqwq | RE | 36ms | 3880kb | C++14 | 910b | 2024-09-30 22:37:39 | 2024-09-30 22:37:40 |
Judging History
answer
#include <bits/stdc++.h>
//#include <windows.h>
#define ED cerr<<endl;
#define TS cerr<<"I AK IOI"<<endl;
#define cr(x) cerr<<x<<endl;
#define cr2(x,y) cerr<<x<<" "<<y<<endl;
#define cr3(x,y,z) cerr<<x<<" "<<y<<" "<<z<<endl;
#define cr4(x,y,z,w) cerr<<x<<" "<<y<<" "<<z<<" "<<w<<endl;
#define pii pair<int,int>
#define mk make_pair
#define fi first
#define se second
//#define int long long
//#define ull unsigned long long
using namespace std;
const int N=1e5+5,INF=2e9,mod=1e9+7;
int t,n;
int ne[N],vis[N];
vector<int> s;
int main()
{
scanf("%d",&t);
while(t--) {
scanf("%d",&n);
for(int i=1;i<=n;++i) {
scanf("%d",&ne[i]);
vis[i]=0;
}
for(int i=1;i<=n;++i) {
if(!vis[i]) {
int p=i;s.clear();
while(!vis[p]) {
s.emplace_back(p);
vis[p]=1,p=ne[p];
}
for(auto it:s) printf("%d ",it);
}
}
puts("");
}
return 0;
}
详细
Test #1:
score: 100
Accepted
time: 1ms
memory: 3796kb
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: 1ms
memory: 3880kb
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 5 6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#4:
score: -100
Runtime Error
input:
1 999995 992870 548521 579550 387108 249895 990007 476463 686591 907510 311379 340877 491996 478527 996443 681309 483046 760005 905577 711115 275827 697004 737465 904964 381424 774578 217570 554656 914370 935328 624905 590395 761191 265062 978389 670994 184745 662928 389422 952905 447853 325275 9796...