提出 #2496928


ソースコード 拡げる

#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#pragma GCC optimize ("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx")
using namespace std;

using ll = long long;
using ull = unsigned long long;
using ld = long double;

#define forn(i, a, n) for (int i = (int)(a); i < (int)(n); ++i)
#define ford(i, a, n) for (int i = (int)(n) - 1; i >= (int)(a); --i)
#define fore(i, a, n) for (int i = (int)(a); i <= (int)(n); ++i)
#define all(a) (a).begin(), (a).end()
#define fs first
#define sn second
#define trace(a)\
    for (auto i : a) cerr << i << ' ';\
    cerr << '\n'
#define eb emplace_back

#ifndef M_PI
const ld M_PI = acos(-1.0);
#endif

template<typename T>
inline void setmax(T& a, T b) {
    if (a < b) a = b;
}

template<typename T>
inline void setmin(T& a, T b) {
    if (a > b) a = b;
}

template<typename T, typename S>
istream& operator>> (istream& in, pair<S, T>& p) {
    in >> p.fs >> p.sn;
    return in;
}
template<typename T, typename S>
ostream& operator<< (ostream& out, pair<S, T>& p) {
    out << p.fs << ' ' << p.sn << ' ';
    return out;
}

template<typename T>
istream& operator>> (istream& in, vector<T>& v) {
    for (T& x : v) in >> x;
    return in;
}
template<typename T>
ostream& operator<< (ostream& out, vector<T>& v) {
    for (T& x : v) out << x << ' ';
    return out;
}

const ld eps = 1e-9;
const int INF = 2000000000;
const ll LINF = 1ll * INF * INF;
const ll MOD = 1000000007;

const int N = 1e5 + 10;
vector<int> e[N];
char used[N];
set<int> comp;

void dfs(int u) {
    if (used[u]) return;
    used[u] = 1;
    comp.insert(u);
    for (int v : e[u])
        dfs(v);
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0); 
    srand((unsigned)chrono::high_resolution_clock::now().time_since_epoch().count());
    int n, m;
    int ans = 0;
    cin >> n >> m;
    vector<int> p(n);
    cin >> p;
    for (int& x : p) --x;
    while (m--) {
        int x, y;
        cin >> x >> y;
        --x, --y;
        e[x].eb(y);
        e[y].eb(x);
    }
    forn(i, 0, n)
        if (!used[i]) {
            comp.clear();
            dfs(i);
            for (int x : comp)
                if (comp.find(p[x]) != comp.end())
                    ++ans;
        }
    cout << ans << '\n';
}

提出情報

提出日時
問題 D - Equals
ユーザ khadaev
言語 C++14 (GCC 5.4.1)
得点 400
コード長 2367 Byte
結果 AC
実行時間 112 ms
メモリ 13312 KiB

ジャッジ結果

セット名 Sample All
得点 / 配点 0 / 0 400 / 400
結果
AC × 4
AC × 23
セット名 テストケース
Sample 0_000.txt, 0_001.txt, 0_002.txt, 0_003.txt
All 0_000.txt, 0_001.txt, 0_002.txt, 0_003.txt, 1_004.txt, 1_005.txt, 1_006.txt, 1_007.txt, 1_008.txt, 1_009.txt, 1_010.txt, 1_011.txt, 1_012.txt, 1_013.txt, 1_014.txt, 1_015.txt, 1_016.txt, 1_017.txt, 1_018.txt, 1_019.txt, 1_020.txt, 1_021.txt, 1_022.txt
ケース名 結果 実行時間 メモリ
0_000.txt AC 3 ms 2560 KiB
0_001.txt AC 3 ms 2560 KiB
0_002.txt AC 3 ms 2560 KiB
0_003.txt AC 3 ms 2560 KiB
1_004.txt AC 19 ms 3584 KiB
1_005.txt AC 38 ms 4096 KiB
1_006.txt AC 112 ms 13312 KiB
1_007.txt AC 3 ms 2560 KiB
1_008.txt AC 3 ms 2560 KiB
1_009.txt AC 3 ms 2560 KiB
1_010.txt AC 3 ms 2560 KiB
1_011.txt AC 3 ms 2560 KiB
1_012.txt AC 3 ms 2560 KiB
1_013.txt AC 3 ms 2688 KiB
1_014.txt AC 3 ms 2688 KiB
1_015.txt AC 3 ms 2560 KiB
1_016.txt AC 3 ms 2560 KiB
1_017.txt AC 3 ms 2688 KiB
1_018.txt AC 18 ms 3712 KiB
1_019.txt AC 19 ms 3072 KiB
1_020.txt AC 19 ms 3072 KiB
1_021.txt AC 19 ms 3200 KiB
1_022.txt AC 99 ms 10624 KiB