Submission #66967287
Source Code Expand
Copy
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
#pragma region
#include<algorithm>
#include<array>
#include<bitset>
#include<cassert>
#include<chrono>
#include<cinttypes>
#include<climits>
#include<cmath>
#include<complex>
#include<cstdio>
#include<cstring>
#include<deque>
#include<functional>
#include<iomanip>
#include<iostream>
#include<iterator>
#include<limits>
#include<map>
#include<numeric>
#include<queue>
#include<random>
#include<set>
#include<sstream>
#include<stack>
#include<string>
#include<tuple>
#include<type_traits>
#include<unordered_map>
#include<unordered_set>
#include<utility>
#include<vector>
using namespace std;
//# pragma GCC target("avx2")
//# pragma GCC optimize("O3")
struct Init{ Init(){ std::cin.tie(0); ios::sync_with_stdio(false); cout << setprecision(20) << fixed; } }init;
using ll = long long;
using ull = unsigned long long;
using ld = long double;
#define all(x) begin((x)), end((x))
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define uq(v) v.erase(unique(begin(v), end(v)), end(v))
#define _overload4(_1,_2,_3,_4,name,...) name
#define _overload3(_1,_2,_3,name,...) name
#define _rep1(n) for(int i = 0; i < n; ++i)
#define _rep2(i,n) for(int i = 0; i < n; ++i)
#define _rep3(i,a,b) for(int i = a; i < b; ++i)
#define _rep4(i,a,b,c) for(int i = a; i < b; i += c)
#define rep(...) _overload4(__VA_ARGS__,_rep4,_rep3,_rep2,_rep1)(__VA_ARGS__)
#define _rrep1(n) for(int i = (n) - 1; i >= 0; --i)
#define _rrep2(i,n) for(int i = (n) - 1; i >= 0; --i)
#define _rrep3(i,a,b) for(int i = (b) - 1; i >= (a); --i)
#define _rrep4(i,a,b,c) for(int i = a + (b - a - 1) / c*c; i >= a; i -= c)
#define rrep(...) _overload4(__VA_ARGS__,_rrep4,_rrep3,_rrep2,_rrep1)(__VA_ARGS__)
template<class T> using pq = priority_queue<T>;
template<class T> using pq_g = priority_queue<T, vector<T>, greater<T>>;
template<class T> bool chmax(T &a, const T &b){ if(a < b){a = b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b){ if(a > b){a = b; return 1; } return 0; }
template<class T> auto min(const T& a){ return *min_element(all(a)); }
template<class T> auto max(const T& a){ return *max_element(all(a)); }
constexpr ull INF = (1ULL << 61) + (1ULL << 30);
constexpr int inf = (1 << 30);
constexpr int dx[] = {1, 0, -1, 0, 1, 1, -1, -1};
constexpr int dy[] = {0, 1 ,0, -1, 1, -1, 1, -1};
#pragma endregion
struct UnionFind{
vector<int> par, rank, siz;
UnionFind(int n): par(n, -1), rank(n, 0), siz(n, 1){}
// x の根を求める
int root(int x){
if(par[x] == -1) return x;
else return par[x] = root(par[x]);
}
// x と y が連結か
bool same(int x, int y){
return root(x) == root(y);
}
// x と y を結ぶ
bool merge(int x, int y){
int rx = root(x), ry = root(y);
if(rx == ry) return false;
if(rank[rx] < rank[ry]) swap(rx, ry);
par[ry] = rx;
if(rank[rx] == rank[ry]) ++rank[rx];
siz[rx] += siz[ry];
return true;
}
// x の連結成分の個数
int size(int x){
return siz[root(x)];
}
};
void solve(){
int N, M; cin >> N >> M;
vector<set<int>> G(N);
vector<int> U(M), V(M);
rep(i, M){
cin >> U[i] >> V[i];
G[--U[i]].insert(--V[i]);
G[V[i]].insert(U[i]);
}
int Q; cin >> Q;
UnionFind uf(N);
rep(i, Q){
int X; cin >> X;
--X;
int u = U[X], v = V[X];
int ur = uf.root(u);
int vr = uf.root(v);
if(ur == vr){
cout << M << "\n";
continue;
}
uf.merge(ur, vr);
int nr = uf.root(ur);
if(nr == ur){
for(auto k: G[vr]){
if(k == ur){
G[ur].erase(vr);
--M;
continue;
}
if(G[ur].contains(k)){
G[k].erase(vr);
--M;
continue;
}
G[ur].insert(k);
G[k].erase(vr);
G[k].insert(ur);
}
G[vr].clear();
}else{
for(auto k: G[ur]){
if(k == vr){
G[vr].erase(ur);
--M;
continue;
}
if(G[vr].contains(k)){
G[k].erase(ur);
--M;
continue;
}
G[vr].insert(k);
G[k].erase(ur);
G[k].insert(vr);
}
G[ur].clear();
}
cout << M << "\n";
}
}
int main(){
int T;
T = 1;
//cin >> T;
rep(i, T) solve();
}
Submission Info
| Submission Time |
|
| Task |
F - Contraction |
| User |
masyumaroo |
| Language |
C++ 23 (gcc 12.2) |
| Score |
525 |
| Code Size |
4827 Byte |
| Status |
AC |
| Exec Time |
600 ms |
| Memory |
65072 KiB |
Compile Error
Main.cpp:1: warning: ignoring ‘#pragma region ’ [-Wunknown-pragmas]
1 | #pragma region
|
Main.cpp:68: warning: ignoring ‘#pragma endregion ’ [-Wunknown-pragmas]
68 | #pragma endregion
|
Judge Result
| Set Name |
Sample |
All |
| Score / Max Score |
0 / 0 |
525 / 525 |
| Status |
|
|
| Set Name |
Test Cases |
| Sample |
example_00.txt |
| All |
example_00.txt, hand_00.txt, hand_01.txt, hand_02.txt, hand_03.txt, hand_04.txt, hand_05.txt, hand_06.txt, hand_07.txt, hand_08.txt, hand_09.txt, hand_10.txt, hand_11.txt, hand_12.txt, hand_13.txt, random_00.txt, random_01.txt, random_02.txt, random_03.txt, random_04.txt, random_05.txt, random_06.txt, random_07.txt, random_08.txt, random_09.txt, random_10.txt, random_11.txt, random_12.txt, random_13.txt, random_14.txt, random_15.txt, random_16.txt, random_17.txt, random_18.txt, random_19.txt, random_20.txt, random_21.txt, random_22.txt, random_23.txt, random_24.txt, random_25.txt, random_26.txt, random_27.txt, random_28.txt, random_29.txt |
| Case Name |
Status |
Exec Time |
Memory |
| example_00.txt |
AC |
1 ms |
3424 KiB |
| hand_00.txt |
AC |
207 ms |
51060 KiB |
| hand_01.txt |
AC |
209 ms |
51064 KiB |
| hand_02.txt |
AC |
465 ms |
65072 KiB |
| hand_03.txt |
AC |
211 ms |
51040 KiB |
| hand_04.txt |
AC |
253 ms |
28096 KiB |
| hand_05.txt |
AC |
21 ms |
3376 KiB |
| hand_06.txt |
AC |
253 ms |
58164 KiB |
| hand_07.txt |
AC |
29 ms |
20692 KiB |
| hand_08.txt |
AC |
146 ms |
50964 KiB |
| hand_09.txt |
AC |
293 ms |
51104 KiB |
| hand_10.txt |
AC |
329 ms |
51072 KiB |
| hand_11.txt |
AC |
382 ms |
51136 KiB |
| hand_12.txt |
AC |
289 ms |
42392 KiB |
| hand_13.txt |
AC |
314 ms |
35444 KiB |
| random_00.txt |
AC |
236 ms |
27816 KiB |
| random_01.txt |
AC |
448 ms |
47816 KiB |
| random_02.txt |
AC |
320 ms |
42864 KiB |
| random_03.txt |
AC |
304 ms |
49704 KiB |
| random_04.txt |
AC |
492 ms |
44060 KiB |
| random_05.txt |
AC |
360 ms |
47696 KiB |
| random_06.txt |
AC |
225 ms |
23616 KiB |
| random_07.txt |
AC |
413 ms |
50968 KiB |
| random_08.txt |
AC |
293 ms |
40444 KiB |
| random_09.txt |
AC |
311 ms |
49996 KiB |
| random_10.txt |
AC |
362 ms |
46560 KiB |
| random_11.txt |
AC |
413 ms |
44256 KiB |
| random_12.txt |
AC |
235 ms |
27360 KiB |
| random_13.txt |
AC |
436 ms |
48412 KiB |
| random_14.txt |
AC |
461 ms |
47924 KiB |
| random_15.txt |
AC |
600 ms |
62772 KiB |
| random_16.txt |
AC |
561 ms |
43164 KiB |
| random_17.txt |
AC |
368 ms |
44016 KiB |
| random_18.txt |
AC |
287 ms |
26772 KiB |
| random_19.txt |
AC |
424 ms |
51084 KiB |
| random_20.txt |
AC |
518 ms |
46844 KiB |
| random_21.txt |
AC |
344 ms |
49736 KiB |
| random_22.txt |
AC |
272 ms |
49236 KiB |
| random_23.txt |
AC |
308 ms |
41724 KiB |
| random_24.txt |
AC |
228 ms |
23620 KiB |
| random_25.txt |
AC |
429 ms |
48396 KiB |
| random_26.txt |
AC |
381 ms |
47948 KiB |
| random_27.txt |
AC |
340 ms |
49728 KiB |
| random_28.txt |
AC |
229 ms |
50828 KiB |
| random_29.txt |
AC |
387 ms |
42676 KiB |