File tree 4 files changed +72
-0
lines changed
4 files changed +72
-0
lines changed Original file line number Diff line number Diff line change
1
+ Case 1: 2
2
+ Case 2: 2
Original file line number Diff line number Diff line change
1
+ 2
2
+ 5 4
3
+ 1 2
4
+ 1 3
5
+ 3 4
6
+ 5 3
7
+
8
+ 4 4
9
+ 1 2
10
+ 1 3
11
+ 4 2
12
+ 4 3
13
+
Original file line number Diff line number Diff line change
1
+ // https://uva.onlinejudge.org/external/117/11770.pdf
2
+ #include < bits/stdc++.h>
3
+ using namespace std ;
4
+ using vi=vector<int >;
5
+ using vvi=vector<vi>;
6
+ using qi=queue<int >;
7
+ int main (){
8
+ ios::sync_with_stdio (0 );
9
+ cin.tie (0 );
10
+ int t,n,m,u,v;
11
+ cin>>t;
12
+ for (int T=1 ;T<=t;T++){
13
+ cin>>n>>m;
14
+ vvi g (n),h (n),c;
15
+ for (int i=0 ;i<m;i++){
16
+ cin>>u>>v;
17
+ u--;v--;
18
+ g[u].push_back (v);
19
+ h[v].push_back (u);
20
+ }
21
+ vi a,s (n),t (n),r (n);
22
+ function<void (int )>dfs1=[&](int i){
23
+ s[i]=1 ;
24
+ for (int j:g[i])
25
+ if (!s[j])dfs1 (j);
26
+ a.push_back (i);
27
+ };
28
+ for (int i=0 ;i<n;i++)
29
+ if (!s[i])dfs1 (i);
30
+ reverse (a.begin (),a.end ());
31
+ function<void (int )>dfs2=[&](int i){
32
+ t[i]=1 ;
33
+ c.back ().push_back (i);
34
+ for (int j:h[i])
35
+ if (!t[j])dfs2 (j);
36
+ };
37
+ for (int i=0 ;i<a.size ();i++)
38
+ if (!t[a[i]]){
39
+ c.push_back (vi ());
40
+ dfs2 (a[i]);
41
+ }
42
+ function<void (int )>dfs3=[&](int i){
43
+ r[i]=1 ;
44
+ for (int j:g[i])
45
+ if (!r[j])dfs3 (j);
46
+ };
47
+ int k=0 ;
48
+ for (vi &x:c)
49
+ if (!r[x[0 ]]){
50
+ k++;
51
+ dfs3 (x[0 ]);
52
+ }
53
+ cout<<" Case " <<T<<" : " <<k<<" \n " ;
54
+ }
55
+ }
Original file line number Diff line number Diff line change @@ -121,6 +121,8 @@ There are solutions for the following
121
121
([ problem site] ( https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=24&page=show_problem&problem=2726 ) )
122
122
1 . [ 11690 - Money Matters] ( 11690.cc )
123
123
([ problem site] ( https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=24&page=show_problem&problem=2737 ) )
124
+ 1 . [ 11770 - Lighting Away] ( 11770.cc )
125
+ ([ problem site] ( https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=24&page=show_problem&problem=2870 ) )
124
126
1 . [ 11838 - Come and Go] ( 11838.cc )
125
127
([ problem site] ( https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&category=24&problem=2938 ) )
126
128
1 . [ 11966 - Galactic Bonding] ( 11966.cc )
You can’t perform that action at this time.
0 commit comments