mickypinata

GRD3-T02: Werewolf

Nov 23rd, 2020 (edited)
116
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.58 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. typedef pair<int, int> pii;
  5.  
  6. const int N = 3000;
  7.  
  8. vector<int> adj[N + 10];
  9. int nVertex, nEdge, Q, limHuman, limWerewolf;
  10.  
  11. int main(){
  12.  
  13.     scanf("%d %d %d", &nVertex, &nEdge, &Q);
  14.     for(int i = 1; i <= nEdge; ++i){
  15.         int u, v;
  16.         scanf("%d %d", &u, &v);
  17.         adj[u].push_back(v);
  18.         adj[v].push_back(u);
  19.     }
  20.  
  21.     for(int q = 1; q <= Q; ++q){
  22.         int st, ed;
  23.         scanf("%d %d %d %d", &st, &ed, &limHuman, &limWerewolf);
  24.         queue<pii> qu;
  25.         vector<vector<bool>> visited(nVertex + 1, vector<bool>(2, false));
  26.         qu.emplace(st, 0);
  27.         visited[st][0] = true;
  28.         bool complete = false;
  29.         while(!qu.empty()){
  30.             int u = qu.front().first;
  31.             int ww = qu.front().second;
  32.             qu.pop();
  33.             if(u == ed && ww == 1){
  34.                 cout << "1\n";
  35.                 complete = true;
  36.                 break;
  37.             }
  38.             if(!visited[u][1] && u >= limHuman && u <= limWerewolf){
  39.                 qu.emplace(u, 1);
  40.                 visited[u][1] = true;
  41.             }
  42.             for(int v : adj[u]){
  43.                 if(ww == 0 && !visited[v][0] && v >= limHuman){
  44.                     qu.emplace(v, 0);
  45.                     visited[v][0] = true;
  46.                 } else if(ww == 1 && !visited[v][1] && v <= limWerewolf){
  47.                     qu.emplace(v, 1);
  48.                     visited[v][1] = true;
  49.                 }
  50.             }
  51.         }
  52.         if(!complete){
  53.             cout << "0\n";
  54.         }
  55.     }
  56.  
  57.     return 0;
  58. }
  59.  
Add Comment
Please, Sign In to add comment