Hlju 1105 CPC meow split set (and query the reverse operation of the Set)

Source: Internet
Author: User

1105: split set of meow
Time Limit: 1 sec memory limit: 128 MB
Submit: 37 solved: 8
[Submit] [Status] [web board] Description

As we all know, doubleq is a DS (Data Structure) powder, and she loves DS most. Now she wants to implement a magic DS and supports the following two operations:
-Delete an edge, expressed as "d x", that is, delete the X edge.
-Check whether two points belong to a set, expressed as "q a B", that is, whether node A and Node B are in the same set. If they are in the same set, output "yes"; otherwise output "NO" (the output does not include quotation marks)

N <= 100000, m <= 100000, q <= 100000

Input

Multiple groups of data.

For each group of data, the first row contains three positive integers, representing the number of nodes in the data structure N, the number of edges m, and the operand Q

The next m row represents the I edge (starting from 1), and the I edge connects the u and v vertices (no duplicate edge, no self ring)
The next row of the Q-row contains a format such as the question description operation.

Output

For each query, the output includes one row, indicating the query result. That is, if two points belong to the same set, "yes" is output; otherwise, "no" is output ".

Sample Input
5 4 61 22 34 51 3Q 1 2D 1Q 1 2Q 3 4D 2Q 1 2
Sample output
YesYesNoNo



Resolution: reverse processing. Because edge deletion is not easy to implement, we can change our thinking. All operations are retained first, and then each operation is executed in reverse order. In this way, deleting an edge is equivalent to not adding this edge, and then performing each operation in reverse order.



AC code:

# Include <cstdio> # include <cstring> # include <iostream> # include <algorithm> using namespace STD; const int maxn = 100000 + 10; typedef struct node {int, b;} edge; edge e [maxn], Q [maxn]; int del [maxn], is_d [maxn]; bool s [maxn]; int par [maxn]; // father [] array char op [maxn] [4]; // Save the inline int getpar (int x) {return x = par [x]? X: par [x] = getpar (par [x]);} inline void unin (int x, int y) {int A = getpar (x ), B = getpar (y); if (! = B) par [a] = B;} int main () {# ifdef sxk freopen ("in.txt", "r", stdin); # endif // sxk STD :: IOS: sync_with_stdio (false); STD: cin. tie (0); int n, m, K; while (scanf ("% d", & N, & M, & K )! = EOF) {memset (is_d, 0, sizeof (is_d); memset (S, false, sizeof (s); memset (E, 0, sizeof (e )); memset (Q, 0, sizeof (q); memset (Del, 0, sizeof (DEL); For (INT I = 1; I <= N; I ++) {Par [I] = I ;}for (INT I = 1; I <= m; I ++) {scanf ("% d ", & E [I]. a, & E [I]. b);} int fo = 0, foo = 0; For (INT I = 1; I <= K; I ++) {scanf ("% s ", & OP [I]); If (OP [I] [0] = 'q') {Foo ++; scanf ("% d ", & Q [Foo]. a, & Q [Foo]. b) ;}else {fo ++; scanf (" % D ", & del [fO]); is_d [del [fO] = 1 ;}}for (INT I = 1; I <= m; I ++) {If (! Is_d [I]) unin (E [I]. a, E [I]. b);} int CNT = Foo; For (INT I = K; I> 0; I --) {If (OP [I] [0] = 'q ') {If (getpar (Q [CNT]. a) = getpar (Q [CNT]. b) s [CNT] = true; else s [CNT] = false; CNT --;} else {unin (E [del [fO]. a, E [del [fO]. b); fo -- ;}}for (INT I = 1; I <= Foo; I ++) printf ("% s \ n ", s [I] = true? "Yes": "no");} return 0 ;}





Hlju 1105 CPC meow split set (and query the reverse operation of the Set)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.