-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path1249B1.cpp
More file actions
56 lines (52 loc) · 1.91 KB
/
1249B1.cpp
File metadata and controls
56 lines (52 loc) · 1.91 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
#include "bits/stdc++.h"
using namespace std;
#define sz(x) ((int)(x).size())
#define all(x) (x).begin(), (x).end()
template<class Fun> class y_combinator_result {
#define endl '\n'
Fun fun_;
public:
template<class T> explicit y_combinator_result(T &&fun): fun_(std::forward<T>(fun)) {}
template<class ...Args> decltype(auto) operator()(Args &&...args) { return fun_(std::ref(*this), std::forward<Args>(args)...); }
};
template<class Fun> decltype(auto) y_combinator(Fun &&fun) { return y_combinator_result<std::decay_t<Fun>>(std::forward<Fun>(fun)); }
template<typename A, typename B> ostream& operator<<(ostream &os, const pair<A, B> &p) { return os << '(' << p.first << ", " << p.second << ')'; }
template<typename T_container, typename T = typename enable_if<!is_same<T_container, string>::value, typename T_container::value_type>::type> ostream& operator<<(ostream &os, const T_container &v) { os << '{'; string sep; for (const T &x : v) os << sep << x, sep = ", "; return os << '}'; }
void dbg_out() { cerr << endl; }
template<typename TT, typename... UU> void dbg_out(TT H, UU... T) { cerr << ' ' << H; dbg_out(T...); }
#ifndef ONLINE_JUDGE
#include "debug.hpp"
#define dbg(...) cerr << "(" << #__VA_ARGS__ << "):", dbg_out(__VA_ARGS__)
#else
#define print(...)
#define dbg(...)
#endif
int64_t link[202], cnt = 1;
int64_t find(int64_t x) {
int b = x;
while(b != link[x]) {
x = link[x];
cnt += 1;
}
return x;
}
void solve(){
int64_t n; cin >> n;
for(int64_t i = 1; i <= n; ++i) cin >> link[i];
for(int64_t i = 1; i <= n; ++i) {
int x = find(link[i]);
x += 0;
cout << cnt << " ";
cnt = 1;
}
cout << "\n";
}
int main(){
ios::sync_with_stdio(false);cin.tie(nullptr);cout.tie(nullptr);
int testt = 1;
cin >> testt;
for (int i = 1; i <= testt; ++i){
// cout << "Case #" << i << ": ";
solve();
}
}