Skip to content

Commit 97d1eea

Browse files
committed
[uva] Add C++ solution for 793 - Network Connections.
1 parent 610d64a commit 97d1eea

File tree

4 files changed

+61
-0
lines changed

4 files changed

+61
-0
lines changed

uva/00793-1.ans

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
1,2
2+
3+
2,0

uva/00793-1.in

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
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

uva/00793.cc

+41
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
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+
}

uva/README.md

+2
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ There are solutions for the following
2525
([problem site](https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&category=6&problem=400))
2626
* [579 - Clock Hands](00579.cc)
2727
([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))
2830
* [10004 - Bicoloring](10004.cc)
2931
([problem site](http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=24&page=show_problem&problem=945))
3032
* [10038 - Jolly Jumpers](10038.cc)

0 commit comments

Comments
 (0)