#include "bits/stdc++.h"
#define ll long long
using namespace std;
const int N=5e5+1,mod=1e9+7;
vector<int>l,r;
vector<vector<int>>v(N),rev(N);
int n,m,A,B;
int x[N],y[N];
bool vis[N],removed[N];
void dfs(int idx){
vis[idx]=1;
for(auto i:v[idx])
if(!vis[i] && !removed[i])
dfs(i);
}
void del(int idx){
vis[idx]=1;
for(auto i:v[idx])
if(!vis[i])
del(i);
}
void delr(int idx){
vis[idx]=1;
for(auto i:rev[idx])
if(!vis[i])
delr(i);
}
int mx[N],mn[N];
int main(){
cin>>n>>m>>A>>B;
for(int i=1;i<=n;i++){
cin>>x[i]>>y[i];
if(x[i]==0)
l.push_back(i);
if(x[i]==A)
r.push_back(i);
}
sort(l.begin(),l.end(),[](int i, int j){
return y[i] < y[j];
});
sort(r.begin(),r.end(),[](int i, int j){
return y[i] < y[j];
});
//reverse(l.begin(),l.end());
while(m--){
int d,c,k;
cin>>c>>d>>k;
v[c].push_back(d);
rev[d].push_back(c);
if(k==2){
v[d].push_back(c);
rev[c].push_back(d);
}
}
vector<int>r1;
for(auto i:l)
del(i);
for(int i=1;i<=n;i++)
if(!vis[i])
removed[i]=1;
memset(vis,0,sizeof vis);
for(auto i:r)
delr(i);
for(int i=1;i<=n;i++)
if(!vis[i])
removed[i]=1;
for(int i=0;i<r.size();i++)
if(!removed[r[i]])
r1.push_back(r[i]);
int szl=l.size(),szr1=r1.size();
memset(vis,0,sizeof vis);
int idx=0;
for(int i=0;i<szl;i++){
if(removed[l[i]])continue;
dfs(l[i]);
while(idx+1<szr1 && vis[r1[idx+1]])
idx++;
mx[i]=idx;
}
memset(vis,0,sizeof vis);
idx=szr1-1;
for(int i=szl-1;i>=0;i--){
if(removed[l[i]])continue;
dfs(l[i]);
while(idx-1>=0 && vis[r1[idx-1]])
idx--;
mn[i]=idx;
}
vector<int>ans;
for(int i=0;i<szl;i++){
if(removed[l[i]]) ans.push_back(0);
else ans.push_back(mx[i]-mn[i]+1);
}
reverse(ans.begin(),ans.end());
for(auto i:ans)cout<<i<<'\n';
return 0;
}
Compilation message
tra.cpp: In function 'int main()':
tra.cpp:69:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
69 | for(int i=0;i<r.size();i++)
| ~^~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
7 ms |
32080 KB |
Output is correct |
2 |
Correct |
7 ms |
32080 KB |
Output is correct |
3 |
Correct |
7 ms |
32080 KB |
Output is correct |
4 |
Correct |
7 ms |
32080 KB |
Output is correct |
5 |
Correct |
7 ms |
30032 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
7 ms |
32080 KB |
Output is correct |
2 |
Correct |
7 ms |
32080 KB |
Output is correct |
3 |
Correct |
8 ms |
32080 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
7 ms |
32080 KB |
Output is correct |
2 |
Correct |
10 ms |
32080 KB |
Output is correct |
3 |
Correct |
8 ms |
32080 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
9 ms |
32080 KB |
Output is correct |
2 |
Correct |
13 ms |
32592 KB |
Output is correct |
3 |
Correct |
11 ms |
32336 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
24 ms |
32592 KB |
Output is correct |
2 |
Correct |
74 ms |
37104 KB |
Output is correct |
3 |
Correct |
39 ms |
34296 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
53 ms |
34044 KB |
Output is correct |
2 |
Correct |
103 ms |
38472 KB |
Output is correct |
3 |
Correct |
57 ms |
31048 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
99 ms |
35724 KB |
Output is correct |
2 |
Correct |
152 ms |
43352 KB |
Output is correct |
3 |
Correct |
179 ms |
42992 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
164 ms |
37704 KB |
Output is correct |
2 |
Correct |
152 ms |
42824 KB |
Output is correct |
3 |
Correct |
250 ms |
43604 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
267 ms |
40008 KB |
Output is correct |
2 |
Correct |
263 ms |
49868 KB |
Output is correct |
3 |
Correct |
431 ms |
53748 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
373 ms |
44360 KB |
Output is correct |
2 |
Correct |
490 ms |
62144 KB |
Output is correct |
3 |
Correct |
398 ms |
54856 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
916 ms |
55736 KB |
Output is correct |
2 |
Correct |
471 ms |
52920 KB |
Output is correct |
3 |
Correct |
759 ms |
68936 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
247 ms |
36168 KB |
Output is correct |
2 |
Correct |
622 ms |
67592 KB |
Output is correct |
3 |
Correct |
721 ms |
62792 KB |
Output is correct |
4 |
Correct |
1018 ms |
74984 KB |
Output is correct |