vitormartinotti

fire_incompleto

Oct 9th, 2025
225
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.67 KB | None | 0 0
  1. #include<bits/stdc++.h>
  2. #define MAXN 100010
  3.  
  4. using namespace std;
  5.  
  6. const int INF = 1e6;
  7.  
  8. int di[] = {0,0,1,-1};
  9. int dj[] = {1,-1,0,0};
  10.  
  11. int marc[MAXN][MAXN], dist[MAXN][MAXN];
  12. char M[MAXN][MAXN];
  13.  
  14. vector<pii> ms;
  15.  
  16. void bfs_ms(){
  17.     memset(dist, MAX_INT, sizeof dist);
  18.     memset(marc, 0, sizeof marc);
  19.  
  20.     queue<pii> q;
  21.     for(auto e : ms){
  22.         q.push(e);
  23.         marc[e.first][e.second] = 1;
  24.         dist[e.first][e.second] = 0;
  25.     }
  26.  
  27.     while(!q.empty()){
  28.         pii v = q.front();
  29.         q.pop();
  30.         int i = v.first;
  31.         int j = v.second;
  32.         for(int k = 0; k < 4; k++){
  33.             int ni = i+di[k];
  34.             int nj = j+dj[k];
  35.             if(ni < 0 || nj < 0 || ni >= n || nj >= m) continue;
  36.             if(M[ni][nj] == '#') continue;
  37.             if(marc[ni][nj] != 0) continue;
  38.             q.push({ni,nj});
  39.             marc[ni][nj] = 1;
  40.             dist[ni][nj] = dist[i][j]+1;
  41.         }
  42.     }
  43. }
  44.  
  45. void bfs(int s){
  46.     memset(marc, 0, sizeof marc);
  47.  
  48.     queue<pii> q;
  49.     q.push(s);
  50.     marc[s.first][s.second] = 1;
  51.     dist[s.first][s.second] = 0;
  52.  
  53.     while(!q.empty()){
  54.         pii v = q.front();
  55.         q.pop();
  56.         int i = v.first;
  57.         int j = v.second;
  58.         for(int k = 0; k < 4; k++){
  59.             int ni = i+di[k];
  60.             int nj = j+dj[k];
  61.             if(ni < 0 || nj < 0 || ni >= n || nj >= m) continue;
  62.             if(M[ni][nj] == '#') continue;
  63.             if(marc[ni][nj] != 0) continue;
  64.             if(!(dist[i][j]+1 < dist[ni][nj])) continue;
  65.             q.push({ni,nj});
  66.             marc[ni][nj] = 1;
  67.             dist[ni][nj] = dist[i][j]+1;
  68.         }
  69.     }
  70. }
  71.  
  72.  
  73. int main(){
  74.  
  75. }
  76.  
Advertisement
Add Comment
Please, Sign In to add comment