#include <bits/stdc++.h>
#include "werewolf.h"
using namespace std;
struct node {
int id;
list<node*> l;
bool v;
};
vector<node> g;
void wolf(node*n, int r, bool w[]){
w[n->id] = true;
for(node* c : n->l){
if(!w[c->id] && c->id <= r) wolf(c, r, w);
}
}
bool human(node* n, int l, bool w[], int r){
n->v = true;
for(node* c : n->l){
if(w[c->id] && (c->id >= l || n->id <= r)) return true;
if(!c->v && c->id >= l && human(c, l, w, r)) return true;
}
return false;
}
vector<int> check_validity(int N, vector<int> X, vector<int> Y, vector<int> S, vector<int> E, vector<int> L, vector<int> R){
g.resize(N);
for(int i = 0;i < N;i++) g[i].id=i;
for(int i = 0;i < X.size();i++){
g[X[i]].l.push_back(&g[Y[i]]);
g[Y[i]].l.push_back(&g[X[i]]);
}
vector<int> ans(S.size(), 0);
for(int i = 0;i < S.size();i++){
for(int j = 0;j < N;j++) g[j].v = false;
bool w[N] = {false};
wolf(&g[E[i]], R[i], w);
if(human(&g[S[i]], L[i], w, R[i])) ans[i] = 1;
}
return ans;
}
Compilation message
werewolf.cpp: In function 'std::vector<int> check_validity(int, std::vector<int>, std::vector<int>, std::vector<int>, std::vector<int>, std::vector<int>, std::vector<int>)':
werewolf.cpp:27:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
27 | for(int i = 0;i < X.size();i++){
| ~~^~~~~~~~~~
werewolf.cpp:32:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
32 | for(int i = 0;i < S.size();i++){
| ~~^~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
0 ms |
292 KB |
Output is correct |
3 |
Correct |
1 ms |
296 KB |
Output is correct |
4 |
Correct |
1 ms |
288 KB |
Output is correct |
5 |
Correct |
1 ms |
204 KB |
Output is correct |
6 |
Correct |
1 ms |
204 KB |
Output is correct |
7 |
Correct |
1 ms |
204 KB |
Output is correct |
8 |
Correct |
1 ms |
204 KB |
Output is correct |
9 |
Correct |
1 ms |
204 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
0 ms |
292 KB |
Output is correct |
3 |
Correct |
1 ms |
296 KB |
Output is correct |
4 |
Correct |
1 ms |
288 KB |
Output is correct |
5 |
Correct |
1 ms |
204 KB |
Output is correct |
6 |
Correct |
1 ms |
204 KB |
Output is correct |
7 |
Correct |
1 ms |
204 KB |
Output is correct |
8 |
Correct |
1 ms |
204 KB |
Output is correct |
9 |
Correct |
1 ms |
204 KB |
Output is correct |
10 |
Correct |
201 ms |
908 KB |
Output is correct |
11 |
Correct |
106 ms |
832 KB |
Output is correct |
12 |
Correct |
14 ms |
972 KB |
Output is correct |
13 |
Correct |
254 ms |
864 KB |
Output is correct |
14 |
Correct |
204 ms |
844 KB |
Output is correct |
15 |
Correct |
286 ms |
1164 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
4040 ms |
34692 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
0 ms |
292 KB |
Output is correct |
3 |
Correct |
1 ms |
296 KB |
Output is correct |
4 |
Correct |
1 ms |
288 KB |
Output is correct |
5 |
Correct |
1 ms |
204 KB |
Output is correct |
6 |
Correct |
1 ms |
204 KB |
Output is correct |
7 |
Correct |
1 ms |
204 KB |
Output is correct |
8 |
Correct |
1 ms |
204 KB |
Output is correct |
9 |
Correct |
1 ms |
204 KB |
Output is correct |
10 |
Correct |
201 ms |
908 KB |
Output is correct |
11 |
Correct |
106 ms |
832 KB |
Output is correct |
12 |
Correct |
14 ms |
972 KB |
Output is correct |
13 |
Correct |
254 ms |
864 KB |
Output is correct |
14 |
Correct |
204 ms |
844 KB |
Output is correct |
15 |
Correct |
286 ms |
1164 KB |
Output is correct |
16 |
Execution timed out |
4040 ms |
34692 KB |
Time limit exceeded |
17 |
Halted |
0 ms |
0 KB |
- |