Submission #854215

# Submission time Handle Problem Language Result Execution time Memory
854215 2023-09-26T11:40:37 Z mychecksedad From Hacks to Snitches (BOI21_watchmen) C++17
0 / 100
137 ms 27148 KB
/* Author : Mychecksdead  */
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define MOD (1000000000+7)
#define MOD1 (998244353)
#define pb push_back
#define all(x) x.begin(), x.end()
#define en cout << '\n'
const int N = 3e5+100, M = 1e5+10, K = 5;



int n, m, k;
array<int, 2> T[N];
vector<int> g[N];
priority_queue<int> best[N];
void solve(){
  cin >> n >> m;
  for(int i = 0; i < m; i++){
    int u, v; cin >> u >> v;
    g[u].pb(v);
    g[v].pb(u);
  }
  for(int i = 1; i <= n; ++i) T[i] = {-1, 0};
  cin >> k;
  for(int i = 1; i <= k; ++i){
    int x; cin >> x;
    for(int j = 0; j < x; ++j){
      int nod; cin >> nod;
      T[nod] = {j, x};
    }
  }
  priority_queue<array<int, 2>> q;
  for(int j = 0; j < K; ++j) best[1].push(j), q.push({-j, 1});
  while(!q.empty()){
    int v = q.top()[1], D = -q.top()[0];
    q.pop();
    if(D > best[v].top()) continue;
    for(int u: g[v]){
      for(int j = 1; j <= K; ++j){
        int DD = D + j;
        if(T[v][0] > -1 && (DD-1) % T[v][1] == T[v][0]) break;
        if(T[v][0] > -1 && T[u][0] > -1 && DD % T[v][1] == T[v][0] && (DD-1) % T[u][1] == T[u][0]){
          continue;
        }
        if(T[u][0] > -1 && DD % T[u][1] == T[u][0]){
          continue;
        }
        if(best[u].size() < K){
          best[u].push(DD);
          q.push({-DD, u});
        }else if(best[u].top() > DD){
          best[u].pop();
          best[u].push(DD);
          q.push({-DD, u});
        } 
      }
    }
  }
  if(best[n].empty()) cout << "impossible";
  else{
    while(best[n].size() > 1) best[n].pop();
    cout << best[n].top();
  }
}


int main(){
  cin.tie(0); ios::sync_with_stdio(0);
  int tt = 1, aa;
  // freopen("in.txt", "r", stdin);
  // freopen("out.txt", "w", stdout);
  while(tt--){
    solve();
  }
  cerr<<"time taken : "<<(float)clock()/CLOCKS_PER_SEC<<" seconds\n";
  return 0;
} 

Compilation message

watchmen.cpp: In function 'int main()':
watchmen.cpp:71:15: warning: unused variable 'aa' [-Wunused-variable]
   71 |   int tt = 1, aa;
      |               ^~
# Verdict Execution time Memory Grader output
1 Correct 29 ms 18012 KB Output is correct
2 Incorrect 137 ms 27148 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 28 ms 17988 KB Output is correct
2 Incorrect 133 ms 26728 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 28 ms 17988 KB Output is correct
2 Incorrect 133 ms 26728 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 28 ms 17988 KB Output is correct
2 Incorrect 133 ms 26728 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 29 ms 18012 KB Output is correct
2 Incorrect 137 ms 27148 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 29 ms 18012 KB Output is correct
2 Incorrect 137 ms 27148 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 29 ms 18012 KB Output is correct
2 Incorrect 137 ms 27148 KB Output isn't correct
3 Halted 0 ms 0 KB -