結果
| 問題 | No.3650 Teleportation Cycles |
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2026-08-28 22:07:44 |
| 言語 | C++23(gcc16) (gcc 16.1.0 + boost 1.90.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,564 bytes |
| 記録 | |
| コンパイル時間 | 1,558 ms |
| コンパイル使用メモリ | 221,044 KB |
| 実行使用メモリ | 18,048 KB |
| 最終ジャッジ日時 | 2026-08-28 22:07:52 |
| 合計ジャッジ時間 | 4,150 ms |
|
ジャッジサーバーID (参考情報) |
judge2_0 / judge3_0 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 10 WA * 26 |
ソースコード
#include <algorithm>
#include <cmath>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stack>
#include <stdio.h>
#include <string>
#include <vector>
using namespace std;
typedef long long ll;
#define rep(i, init, end) for(ll i = init; i < end; i++)
#define REP(i, init, end) for(ll i = init; i < end + 1; i++)
#define rev(i, end, init) for(ll i = init - 1; i >= end; i--)
#define REV(i, end, init) for(ll i = init; i >= end; i--)
#define PI 3.14159265359
#define EPS 0.0000000001
// #define MOD 1000000007
//cout << std::fixed << std::setprecision(15) << y << endl;
int main(){
ll N;
cin >> N;
ll A[N + 1];
vector<ll> from[N + 1];
rep(i, 1, N + 1){
cin >> A[i];
from[A[i]].push_back(i);
}
ll fromCount[N + 1];
rep(i, 1, N + 1){
fromCount[i] = from[i].size();
}
bool visited[N + 1];
rep(i, 1, N + 1){
visited[i] = false;
}
ll ans = 0;
rep(i, 1, N + 1){
if(!visited[i] && fromCount[i] > 0){
stack<ll> st;
st.push(i);
ll p;
while(!st.empty()){
p = st.top();
st.pop();
if(visited[p]){
if(p == i){
ans++;//cout << "i: " << i << endl;
}
continue;
}
visited[p] = true;
st.push(A[p]);
}
}
}
cout << ans << endl;
return 0;
}