Submission #274855

#TimeUsernameProblemLanguageResultExecution timeMemory
274855Haunted_CppWerewolf (IOI18_werewolf)C++17
15 / 100
4021 ms41360 KiB
#include "werewolf.h" #include <bits/stdc++.h> using namespace std; const int MAX_N = 2e5 + 5; vector<vector<int>> g(MAX_N); vector<int> check_validity(int N, vector<int> X, vector<int> Y, vector<int> S, vector<int> E, vector<int> L, vector<int> R) { for (int i = 0; i < (int) X.size(); i++) { const int st = X[i]; const int et = Y[i]; g[st].emplace_back(et); g[et].emplace_back(st); } int Q = S.size(); vector<int> A(Q); auto Bfs = [&](int source, int dest, int evitar_humano, int evitar_lobo) { vector<vector<int>> dist(N, vector<int>(2, 1e9)); queue<pair<int, int>> q; if (source >= evitar_humano) { dist[source][0] = 0; q.push({source, 0}); } if (source >= evitar_humano && source <= evitar_lobo) { dist[source][1] = 0; q.push({source, 1}); } while(!q.empty()) { int node = q.front().first; int forma = q.front().second; q.pop(); for (auto to : g[node]) { if (forma == 0 && to < evitar_humano) continue; if (forma == 1 && to > evitar_lobo) continue; if(forma == 1 && dist[to][1] > dist[node][1] + 1) { dist[to][1] = dist[node][1] + 1; q.push({to, 1}); } if (forma == 0) { if (dist[to][0] > dist[node][0] + 1) { dist[to][0] = dist[node][0] + 1; q.push({to, 0}); } if (to >= evitar_humano && to <= evitar_lobo && dist[to][1] > dist[node][0] + 1) { dist[to][1] = dist[node][0] + 1; q.push({to, 1}); } } } } return (dist[dest][1] < 1e7); }; for (int i = 0; i < Q; i++) { const int cidade_inicial = S[i]; const int cidade_final = E[i]; A[i] = Bfs(cidade_inicial, cidade_final, L[i], R[i]); } return A; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...