#include<bits/stdc++.h>
#include "werewolf.h"
using namespace std;
const int MAX_SOM=200*1000+5,MAX_REQ=200*1000+5;
int nbSom,nbAre,nbReq,numEuler;
int pere[MAX_SOM];
vector<int> adjaGrand[MAX_SOM],adjaPetit[MAX_SOM];
vector<pair<int,int>> reqHom[MAX_SOM],reqLoup[MAX_SOM];
int numHom[MAX_REQ],numLoup[MAX_REQ];
vector<int> rep;
int pereHom[MAX_SOM],pereLoup[MAX_SOM];
vector<int> filsHom[MAX_SOM],filsLoup[MAX_SOM];
int eulerHomme[MAX_SOM][2],eulerLoup[MAX_SOM][2];
int idSom[MAX_SOM];
vector<tuple<int,int,int>> quest[MAX_SOM];
vector<int> enCours;
int dessus[MAX_SOM],somTot[MAX_SOM];
int diff[MAX_SOM];
int find(int pos) {
if (pos!=pere[pos]) {
pere[pos]=find(pere[pos]);
}
return pere[pos];
}
void DFS_homme(int pos) {
numEuler++;
idSom[numEuler]=pos;
eulerHomme[pos][0]=numEuler;
for (int i:filsHom[pos]) {
DFS_homme(i);
}
eulerHomme[pos][1]=numEuler;
}
void DFS_loup(int pos) {
numEuler++;
eulerLoup[pos][0]=numEuler;
for (int i:filsLoup[pos]) {
DFS_loup(i);
}
eulerLoup[pos][1]=numEuler;
}
bool inclusLoup(int petit,int grand) {
return (eulerLoup[grand][0]<=eulerLoup[petit][0] and eulerLoup[grand][1]>=eulerLoup[petit][1]);
}
void remonte(int pos) {
somTot[pos]=dessus[pos];
for (int i:filsLoup[pos]) {
remonte(i);
somTot[pos]+=somTot[i];
}
}
int calc(int pos) {
int ans=somTot[pos];
for (int i:enCours) {
if (inclusLoup(i,pos)) {
ans++;
}
}
return ans;
}
vector<int> check_validity(int N,vector<int> X,vector<int> Y,vector<int> S,vector<int> E,vector<int> L,vector<int> R) {
nbSom=N;
nbAre=X.size();
nbReq=S.size();
int debAre,finAre;
for (int i=0;i<nbAre;i++) {
debAre=min(X[i],Y[i]);
finAre=max(X[i],Y[i]);
adjaGrand[debAre].push_back(finAre);
adjaPetit[finAre].push_back(debAre);
}
for (int i=0;i<nbReq;i++) {
reqHom[L[i]].push_back({S[i],i});
reqLoup[R[i]].push_back({E[i],i});
}
for (int i=0;i<nbSom;i++) {
pere[i]=i;
}
for (int i=nbSom-1;i>=0;i--) {
for (int j:adjaGrand[i]) {
if (find(j)!=i) {
pereHom[find(j)]=i;
filsHom[i].push_back(find(j));
pere[find(j)]=i;
}
}
for (auto j:reqHom[i]) {
numHom[j.second]=find(j.first);
}
}
for (int i=0;i<nbSom;i++) {
pere[i]=i;
}
for (int i=0;i<nbSom;i++) {
for (int j:adjaPetit[i]) {
if (find(j)!=i) {
pereLoup[find(j)]=i;
filsLoup[i].push_back(find(j));
pere[find(j)]=i;
}
}
for (auto j:reqLoup[i]) {
numLoup[j.second]=find(j.first);
}
}
/*for (int i=0;i<nbReq;i++) {
cout<<numHom[i]<<" "<<numLoup[i]<<endl;
}*/
numEuler=-1;
DFS_homme(0);
DFS_loup(nbSom-1);
/*for (int i=0;i<nbSom;i++) {
cout<<i<<" : ";
for (int j:filsHom[i]) {
cout<<j<<" ";
}
cout<<endl;
}
for (int i=0;i<nbSom;i++) {
cout<<i<<" : ";
for (int j:filsLoup[i]) {
cout<<j<<" ";
}
cout<<endl;
}
for (int i=0;i<nbSom;i++) {
cout<<i<<" : "<<eulerLoup[i][0]<<" "<<eulerLoup[i][1]<<endl;
}*/
for (int i=0;i<nbReq;i++) {
if (eulerHomme[numHom[i]][0]>0) {
quest[eulerHomme[numHom[i]][0]-1].push_back(make_tuple(numLoup[i],i,-1)); ////à voir
}
quest[eulerHomme[numHom[i]][1]].push_back(make_tuple(numLoup[i],i,1)); ////à voir
}
for (int i=0;i<nbSom;i++) {
if(i%(int)sqrt(nbSom)==0) {
for (int j:enCours) {
dessus[j]++;
}
enCours.clear();
remonte(nbSom-1);
}
enCours.push_back(idSom[i]);
for (auto j:quest[i]) {
diff[get<1>(j)]+=calc(get<0>(j))*get<2>(j);
}
}
for (int i=0;i<nbReq;i++) {
if (diff[i]<=0) {
rep.push_back(0);
}
else {
rep.push_back(1);
}
}
return rep;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
6 ms |
40540 KB |
Output is correct |
2 |
Correct |
6 ms |
40540 KB |
Output is correct |
3 |
Correct |
6 ms |
40284 KB |
Output is correct |
4 |
Correct |
6 ms |
40284 KB |
Output is correct |
5 |
Correct |
6 ms |
40320 KB |
Output is correct |
6 |
Correct |
6 ms |
40436 KB |
Output is correct |
7 |
Correct |
7 ms |
40436 KB |
Output is correct |
8 |
Correct |
6 ms |
40284 KB |
Output is correct |
9 |
Correct |
7 ms |
40284 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
6 ms |
40540 KB |
Output is correct |
2 |
Correct |
6 ms |
40540 KB |
Output is correct |
3 |
Correct |
6 ms |
40284 KB |
Output is correct |
4 |
Correct |
6 ms |
40284 KB |
Output is correct |
5 |
Correct |
6 ms |
40320 KB |
Output is correct |
6 |
Correct |
6 ms |
40436 KB |
Output is correct |
7 |
Correct |
7 ms |
40436 KB |
Output is correct |
8 |
Correct |
6 ms |
40284 KB |
Output is correct |
9 |
Correct |
7 ms |
40284 KB |
Output is correct |
10 |
Correct |
11 ms |
41308 KB |
Output is correct |
11 |
Correct |
11 ms |
41308 KB |
Output is correct |
12 |
Correct |
11 ms |
41176 KB |
Output is correct |
13 |
Correct |
11 ms |
41408 KB |
Output is correct |
14 |
Correct |
10 ms |
41272 KB |
Output is correct |
15 |
Correct |
12 ms |
41308 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3024 ms |
94404 KB |
Output is correct |
2 |
Correct |
1166 ms |
97512 KB |
Output is correct |
3 |
Correct |
1607 ms |
94700 KB |
Output is correct |
4 |
Correct |
2201 ms |
93376 KB |
Output is correct |
5 |
Correct |
2259 ms |
93424 KB |
Output is correct |
6 |
Correct |
2815 ms |
94460 KB |
Output is correct |
7 |
Correct |
2868 ms |
90820 KB |
Output is correct |
8 |
Correct |
1135 ms |
97516 KB |
Output is correct |
9 |
Correct |
1520 ms |
91832 KB |
Output is correct |
10 |
Correct |
2164 ms |
91720 KB |
Output is correct |
11 |
Correct |
2364 ms |
91904 KB |
Output is correct |
12 |
Correct |
3023 ms |
92560 KB |
Output is correct |
13 |
Correct |
1092 ms |
106656 KB |
Output is correct |
14 |
Correct |
1078 ms |
106608 KB |
Output is correct |
15 |
Correct |
1012 ms |
106428 KB |
Output is correct |
16 |
Correct |
1016 ms |
106684 KB |
Output is correct |
17 |
Correct |
3006 ms |
90768 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
6 ms |
40540 KB |
Output is correct |
2 |
Correct |
6 ms |
40540 KB |
Output is correct |
3 |
Correct |
6 ms |
40284 KB |
Output is correct |
4 |
Correct |
6 ms |
40284 KB |
Output is correct |
5 |
Correct |
6 ms |
40320 KB |
Output is correct |
6 |
Correct |
6 ms |
40436 KB |
Output is correct |
7 |
Correct |
7 ms |
40436 KB |
Output is correct |
8 |
Correct |
6 ms |
40284 KB |
Output is correct |
9 |
Correct |
7 ms |
40284 KB |
Output is correct |
10 |
Correct |
11 ms |
41308 KB |
Output is correct |
11 |
Correct |
11 ms |
41308 KB |
Output is correct |
12 |
Correct |
11 ms |
41176 KB |
Output is correct |
13 |
Correct |
11 ms |
41408 KB |
Output is correct |
14 |
Correct |
10 ms |
41272 KB |
Output is correct |
15 |
Correct |
12 ms |
41308 KB |
Output is correct |
16 |
Correct |
3024 ms |
94404 KB |
Output is correct |
17 |
Correct |
1166 ms |
97512 KB |
Output is correct |
18 |
Correct |
1607 ms |
94700 KB |
Output is correct |
19 |
Correct |
2201 ms |
93376 KB |
Output is correct |
20 |
Correct |
2259 ms |
93424 KB |
Output is correct |
21 |
Correct |
2815 ms |
94460 KB |
Output is correct |
22 |
Correct |
2868 ms |
90820 KB |
Output is correct |
23 |
Correct |
1135 ms |
97516 KB |
Output is correct |
24 |
Correct |
1520 ms |
91832 KB |
Output is correct |
25 |
Correct |
2164 ms |
91720 KB |
Output is correct |
26 |
Correct |
2364 ms |
91904 KB |
Output is correct |
27 |
Correct |
3023 ms |
92560 KB |
Output is correct |
28 |
Correct |
1092 ms |
106656 KB |
Output is correct |
29 |
Correct |
1078 ms |
106608 KB |
Output is correct |
30 |
Correct |
1012 ms |
106428 KB |
Output is correct |
31 |
Correct |
1016 ms |
106684 KB |
Output is correct |
32 |
Correct |
3006 ms |
90768 KB |
Output is correct |
33 |
Correct |
3103 ms |
94340 KB |
Output is correct |
34 |
Correct |
176 ms |
82376 KB |
Output is correct |
35 |
Correct |
2540 ms |
97404 KB |
Output is correct |
36 |
Correct |
3067 ms |
95356 KB |
Output is correct |
37 |
Correct |
2669 ms |
96296 KB |
Output is correct |
38 |
Correct |
3052 ms |
95872 KB |
Output is correct |
39 |
Correct |
1138 ms |
106488 KB |
Output is correct |
40 |
Correct |
2112 ms |
102128 KB |
Output is correct |
41 |
Correct |
2728 ms |
94664 KB |
Output is correct |
42 |
Correct |
2913 ms |
91640 KB |
Output is correct |
43 |
Correct |
2329 ms |
103536 KB |
Output is correct |
44 |
Correct |
2663 ms |
95928 KB |
Output is correct |
45 |
Correct |
1016 ms |
104492 KB |
Output is correct |
46 |
Correct |
1016 ms |
104528 KB |
Output is correct |
47 |
Correct |
960 ms |
106684 KB |
Output is correct |
48 |
Correct |
1010 ms |
106680 KB |
Output is correct |
49 |
Correct |
977 ms |
106680 KB |
Output is correct |
50 |
Correct |
958 ms |
106504 KB |
Output is correct |
51 |
Correct |
2137 ms |
100932 KB |
Output is correct |
52 |
Correct |
2173 ms |
100592 KB |
Output is correct |