#include "werewolf.h"
#include <bits/stdc++.h>
#include <string>
#include <iostream>
#include <cmath>
#include <numeric>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<int, int> pi;
typedef pair<int, int> pl;
typedef pair<ld, ld> pd;
typedef vector<int> vi;
typedef vector<bool> vb;
typedef vector<vector<int>> vvi;
typedef vector<ld> vd;
typedef vector<long> vl;
typedef vector<pi> vpi;
typedef vector<pl> vpl;
#define FOR(i, a, b) for (int i = a; i < (b); i++)
#define F0R(i, a) for (int i = 0; i < (a); i++)
#define FORd(i, a, b) for (int i = (b)-1; i >= a; i--)
#define F0Rd(i, a) for (int i = (a)-1; i >= 0; i--)
#define trav(a, x) for (auto &a : x)
#define uid(a, b) uniform_int_distribution<int>(a, b)(rng)
#define len(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define F first
#define nl endl
#define S second
#define lb lower_bound
#define ub upper_bound
#define aint(x) x.begin(), x.end()
#define raint(x) x.rbegin(), x.rend()
#define ins insert
const int MOD = 1000000007;
int M,Q,N;
vvi paths(2e5+6,vi());
bool changed = 0;
int set_dist(int a,int b){
if(a==2)return 2;
if(a != 3)return a;
changed = 1;
return b;
}
int dfs(int S,int E,int L, int R){
vi dist(N,3);
vi prev_changed(N,0);
priority_queue<int> pq;
pq.push(S);
dist[S] = 0;
while(!pq.empty()){
int node = pq.top();pq.pop();
if(dist[node] == 3)continue;
for(int i:paths[node]){
changed = 0;
// cout << node << " " << dist[node] << " " << i << " " << dist[i] << endl;
if(dist[node] == 0){
if(i>=L && i<=R){
prev_changed[i] = 1;
dist[i] = set_dist(dist[i],2);
}
if(i>R)dist[i] = set_dist(dist[i],0);
}
if(dist[node] == 1){
if(i<L)dist[i] = set_dist(dist[i],1);
}
if(dist[node] == 2){
if(i>=L && i<=R){
prev_changed[i] = 1;
dist[i] = set_dist(dist[i],2);
}
if(i<L)dist[i] = set_dist(dist[i],1);
}
if(changed){
pq.push(i);
if(prev_changed[node])prev_changed[i] = 1;
}
}
}
// for(int i:dist)cout << i << " ";
// cout << endl;
return ((dist[E] == 1) || (dist[E] == 2 && prev_changed[E] == 1));
}
vi check_validity(int n, vi X, vi Y, vi S, vi E ,vi L, vi R) {
N = n;M = X.size(); Q = L.size();
vi ans(Q);
FOR(i,0,M){
paths[X[i]].pb(Y[i]);
paths[Y[i]].pb(X[i]);
}
FOR(i,0,Q){
ans[i] = dfs(S[i],E[i],L[i],R[i]);
}
return ans;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
4 ms |
4956 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
4 ms |
4956 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
4061 ms |
31448 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
4 ms |
4956 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |