Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- int main(){
- int tc;
- scanf("%d", &tc);
- for(int tr = 1; tr <= tc; tr++){
- int n, m;
- scanf("%d %d", &n, &m);
- int graph[n][n];
- for(int r = 0; r < n; r++){
- for(int c = 0; c < n; c++){
- graph[r][c] = 0;
- }
- }
- for(int i = 0; i < m; i++){
- int r, c;
- scanf("%d %d", &r, &c);
- graph[r-1][c-1]++;
- }
- int pom = 0;
- for(int p = 0; p < n; p++){
- int out = 0;
- int in = 0;
- for(int c = 0; c < n; c++){
- if(graph[p][c] > 0) out++;
- }
- for(int r = 0; r < n; r++){
- if(graph[r][p] > 0) in++;
- }
- //cout << "p = " << p << " in: " << in << " Out: " << out << endl;
- if((in > 0 && out == 0) || (out > 0 && in == 0)) pom++;
- }
- printf("Case %d: %d\n",tr, pom);
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement