File tree 4 files changed +61
-0
lines changed
4 files changed +61
-0
lines changed Original file line number Diff line number Diff line change
1
+ 1,2
2
+
3
+ 2,0
Original file line number Diff line number Diff line change
1
+ 2
2
+
3
+ 10
4
+ c 1 5
5
+ c 2 7
6
+ q 7 1
7
+ c 3 9
8
+ q 9 6
9
+ c 2 5
10
+ q 7 5
11
+
12
+ 1
13
+ q 1 1
14
+ c 1 1
15
+ q 1 1
Original file line number Diff line number Diff line change
1
+ // https://uva.onlinejudge.org/external/7/793.pdf
2
+ #include < bits/stdc++.h>
3
+ using namespace std ;
4
+ using vi=vector<int >;
5
+ int main (){
6
+ int t,n,u,v;
7
+ cin>>t;
8
+ while (t--){
9
+ cin>>n;
10
+ string l;
11
+ getline (cin,l);
12
+ vi s=vi (n, 1 ),p=vi (n);
13
+ for (int i=0 ;i<n;i++)p[i]=i;
14
+ function<int (int )>find=[&](int i){
15
+ if (i==p[i])return i;
16
+ return p[i]=find (p[i]);
17
+ };
18
+ function<void (int ,int )>unite=[&](int i, int j){
19
+ i=find (i);
20
+ j=find (j);
21
+ if (i==j)return ;
22
+ if (s[i]<s[j])swap (i,j);
23
+ s[i]+=s[j];
24
+ p[j]=i;
25
+ };
26
+ int a=0 ,b=0 ;
27
+ while (1 ){
28
+ getline (cin,l);
29
+ if (l.empty ())break ;
30
+ stringstream in (l);
31
+ char q;
32
+ in>>q>>u>>v;
33
+ u--;v--;
34
+ if (q==' c' )unite (u,v);
35
+ else if (find (u)==find (v))a++;
36
+ else b++;
37
+ }
38
+ cout<<a<<" ," <<b<<" \n " ;
39
+ if (t)cout<<" \n " ;
40
+ }
41
+ }
Original file line number Diff line number Diff line change @@ -25,6 +25,8 @@ There are solutions for the following
25
25
([ problem site] ( https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&category=6&problem=400 ) )
26
26
* [ 579 - Clock Hands] ( 00579.cc )
27
27
([ problem site] ( http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=24&page=show_problem&problem=520 ) )
28
+ * [ 793 - Network Connections] ( 00793.cc )
29
+ ([ problem site] ( http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=24&page=show_problem&problem=734 ) )
28
30
* [ 10004 - Bicoloring] ( 10004.cc )
29
31
([ problem site] ( http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=24&page=show_problem&problem=945 ) )
30
32
* [ 10038 - Jolly Jumpers] ( 10038.cc )
You can’t perform that action at this time.
0 commit comments