File tree 4 files changed +62
-0
lines changed
4 files changed +62
-0
lines changed Original file line number Diff line number Diff line change
1
+ 1
Original file line number Diff line number Diff line change
1
+ 1
2
+ 3 2
3
+ 1 2
4
+ 2 3
Original file line number Diff line number Diff line change
1
+ // https://uva.onlinejudge.org/external/115/11504.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
+ while (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<<k<<" \n " ;
54
+ }
55
+ }
Original file line number Diff line number Diff line change @@ -111,6 +111,8 @@ There are solutions for the following
111
111
([ problem site] ( https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=24&page=show_problem&problem=2409 ) )
112
112
1 . [ 11503 - Virtual Friends] ( 11503.cc )
113
113
([ problem site] ( https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=24&page=show_problem&problem=2498 ) )
114
+ 1 . [ 11504 - Dominos] ( 11504.cc )
115
+ ([ problem site] ( https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=24&page=show_problem&problem=2499 ) )
114
116
1 . [ 11518 - Dominos 2] ( 11518.cc )
115
117
([ problem site] ( https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=24&page=show_problem&problem=2513 ) )
116
118
1 . [ 11550 - Demanding Dillema] ( 11550.cc )
You can’t perform that action at this time.
0 commit comments