Advertisement
Manioc

minhocão

Dec 1st, 2017
112
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.13 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2.  
  3. using namespace std;
  4. bool vis[3007];
  5. vector<int> grafo[3007];
  6. int planetas, kek;
  7.  
  8. void dfs(int no){
  9.     vis[no] = true;
  10.     kek++;
  11.     for(int i = 0; i < grafo[no].size(); i++){
  12.         if(!vis[grafo[no][i]]){
  13.             dfs(grafo[no][i]);
  14.         }
  15.     }
  16. }
  17.  
  18. int resp(){
  19.     if(kek < planetas) {
  20.         printf("N\n");
  21.         return 0;
  22.     }
  23.     kek = 0;
  24.     for(int i = 0; i < planetas; i++) vis[i] = 0;
  25.     dfs(planetas);
  26.     if(kek < planetas) {
  27.         printf("N\n");
  28.         return 0;
  29.     }
  30.    
  31.     printf("S\n");
  32.     return 0;
  33. }
  34.  
  35. int main(){
  36.     int cont = 1;
  37.     while(true){
  38.         int buracos;
  39.         kek = 0;
  40.         scanf("%d %d", &planetas, &buracos);
  41.         if(!(planetas + buracos)) break;
  42.  
  43.         for(int i = 1; i <= planetas; i++) {
  44.             grafo[i].clear();
  45.             vis[i] = 0;
  46.         }
  47.         for(int i = 0; i < buracos; i++){
  48.             int x, y;
  49.             cin >> x >> y;
  50.             grafo[x].push_back(y);
  51.         }
  52.         printf("Teste %d\n", cont++);
  53.         dfs(1);
  54.         resp();
  55.         printf("\n");
  56.     }
  57.     return 0;
  58. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement