Submission #2501774
Source Code Expand
#include <bits/stdc++.h> // iostream is too mainstream #include <cstdio> // bitch please #include <iostream> #include <algorithm> #include <cstdlib> #include <vector> #include <set> #include <map> #include <queue> #include <stack> #include <list> #include <cmath> #include <iomanip> #include <time.h> #define dibs reserve #define OVER9000 1234567890 #define ALL_THE(CAKE,LIE) for(auto LIE =CAKE.begin(); LIE != CAKE.end(); LIE++) #define tisic 47 #define soclose 1e-8 #define chocolate win // so much chocolate #define patkan 9 #define ff first #define ss second #define abs(x) ((x < 0)?-(x):x) #define uint unsigned int #define dbl long double #define pi 3.14159265358979323846 using namespace std; // mylittledoge typedef long long cat; #ifdef DONLINE_JUDGE // palindromic tree is better than splay tree! #define lld I64d #endif int main() { cin.sync_with_stdio(0); cin.tie(0); cout << fixed << setprecision(10); int N, M; cin >> N >> M; vector<int> P(N); vector< vector<int> > G(N); for(int i = 0; i < N; i++) cin >> P[i]; for(int i = 0; i < M; i++) { int u, v; cin >> u >> v; G[--u].push_back(--v); G[v].push_back(u); } vector<int> comp(N, -1); int C = 0; for(int i = 0; i < N; i++) if(comp[i] == -1) { queue<int> q; comp[i] = C; q.push(i); while(!q.empty()) { ALL_THE(G[q.front()], it) if(comp[*it] == -1) { comp[*it] = C; q.push(*it); } q.pop(); } C++; } vector<int> pos(N); for(int i = 0; i < N; i++) pos[P[i]-1] = i; int ans = 0; for(int i = 0; i < N; i++) if(comp[i] == comp[pos[i]]) ans++; cout << ans << "\n"; return 0;} // look at my code // my code is amazing
Submission Info
Submission Time | |
---|---|
Task | D - Equals |
User | xellos |
Language | C++14 (GCC 5.4.1) |
Score | 400 |
Code Size | 1719 Byte |
Status | AC |
Exec Time | 55 ms |
Memory | 6912 KB |
Judge Result
Set Name | Sample | All | ||||
---|---|---|---|---|---|---|
Score / Max Score | 0 / 0 | 400 / 400 | ||||
Status |
|
|
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 | 16 ms | 1280 KB |
1_005.txt | AC | 47 ms | 4736 KB |
1_006.txt | AC | 54 ms | 6912 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 | 2 ms | 384 KB |
1_018.txt | AC | 16 ms | 1408 KB |
1_019.txt | AC | 27 ms | 3840 KB |
1_020.txt | AC | 27 ms | 3840 KB |
1_021.txt | AC | 33 ms | 3840 KB |
1_022.txt | AC | 55 ms | 6656 KB |