Submission #2559230


Source Code Expand

#include<bits/stdc++.h>

using namespace std;

vector<vector<int> > graph;
bitset<100000>vis;
bool connects(int a, int b){
    if(a == b) return true;
    bool ans = false;
    vis.set(a,1);
    for(int i = 0; i < graph[a].size() and !ans; i++){
        if(!vis.test(graph[a][i]))
            ans = connects(graph[a][i], b);
    }
    return ans;
}


int main(){

    ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); cout.precision(20);


    int n, m, a, b;
    cin >> n >> m;
    vector<int>p(n);
    for(int i = 0; i < n; i++){
        cin >> p[i];
        p[i]--;
    }

    graph = vector<vector<int> >(n, vector<int>());
    for(int i = 0; i < m; i++){
        cin >> a >> b;
        a--; b--;
        graph[a].push_back(b);
        graph[b].push_back(a);
    }

    int ans = 0;
    for(int i = 0; i < n; i++){
        vis.reset();
        ans += connects(p[i], i);


    }
    cout << ans << endl;
}   

Submission Info

Submission Time
Task D - Equals
User Albert
Language C++14 (GCC 5.4.1)
Score 0
Code Size 973 Byte
Status TLE
Exec Time 2104 ms
Memory 10880 KB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 0 / 400
Status
AC × 4
AC × 21
TLE × 2
Set Name Test Cases
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
Case Name Status Exec Time Memory
0_000.txt AC 1 ms 256 KB
0_001.txt AC 1 ms 256 KB
0_002.txt AC 1 ms 256 KB
0_003.txt AC 1 ms 256 KB
1_004.txt AC 19 ms 1280 KB
1_005.txt AC 221 ms 3968 KB
1_006.txt TLE 2104 ms 10880 KB
1_007.txt AC 1 ms 256 KB
1_008.txt AC 1 ms 256 KB
1_009.txt AC 1 ms 256 KB
1_010.txt AC 1 ms 256 KB
1_011.txt AC 1 ms 256 KB
1_012.txt AC 1 ms 256 KB
1_013.txt AC 1 ms 256 KB
1_014.txt AC 2 ms 384 KB
1_015.txt AC 2 ms 256 KB
1_016.txt AC 2 ms 256 KB
1_017.txt AC 9 ms 384 KB
1_018.txt AC 27 ms 1408 KB
1_019.txt AC 38 ms 3072 KB
1_020.txt AC 38 ms 3072 KB
1_021.txt AC 39 ms 3072 KB
1_022.txt TLE 2104 ms 7040 KB