This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include "bits/stdc++.h"
#define F first
#define S second
#define ll long long
#define pii pair<int,int>
const int mxN = 1e6 + 5;
const int mod = 1e9 + 7;
using namespace std;
pii a[mxN];
set<pii>s,e;
vector<vector<int>>v,v1;
bool vis[mxN];
int id[mxN];
int l[mxN],r[mxN];
int mx;
int mn;
int sz;
int ans[mxN];
void dfs(int u){
mx = max(mx,id[u]);
if(id[u]) mn = min(mn,id[u]);
vis[u] = 1;
for(auto x : v[u]){
if(vis[x]) continue;
dfs(x);
}
}
void dfs1(int u){
vis[u] = 1;
for(auto x : v1[u]){
if(vis[x]) continue;
dfs1(x);
}
}
signed main(){
// ios_base::sync_with_stdio(0);
// cin.tie(0);
// cout.tie(0);
int n,m,A,B;
cin >>n>>m>>A>>B;
vector<pii>og;
for(int i = 1;i <= n;i++){
cin>>a[i].F>>a[i].S;
if(a[i].F == 0) {
s.insert({a[i].S,i});
og.push_back({a[i].S,i});
}
if(a[i].F == A) e.insert({a[i].S,i});
}
sort(og.begin(),og.end());
reverse(og.begin(),og.end());
sz = s.size();
v.resize(n + 4);
v1.resize(n + 4);
for(int i = 1;i <= m;i++){
int x,y,t;
cin >>x>>y>>t;
v[x].push_back(y);
v1[y].push_back(x);
if(t == 2) v[y].push_back(x);
if(t == 2) v1[x].push_back(y);
}
queue<pii>rem;
for(auto x : s){
dfs(x.S);
}
for(auto x : e){
if(!vis[x.S]) rem.push(x);
}
while(rem.size()){
e.erase(rem.front());
rem.pop();
}
memset(vis,0,sizeof vis);
for(auto x : e){
dfs1(x.S);
}
for(auto x : s){
if(!vis[x.S]) rem.push(x);
}
while(rem.size()){
s.erase(rem.front());
rem.pop();
}
memset(vis,0,sizeof vis);
int ids = 1;
for(auto x : e) id[x.S] = ids++;
vector<pii>temp;
int prev;
for(auto x : s){
mx = 0;
// cout<<x.S<<' ';
dfs(x.S);
if(mx == 0) mx = r[prev];
r[x.S] = mx;
temp.push_back(x);
prev = x.S;
}
// cout<<'\n';
memset(vis,0,sizeof vis);
reverse(temp.begin(),temp.end());
for(auto x : temp){
mn = 1e9;
dfs(x.S);
if(mn == 1e9) mn = l[prev];
l[x.S] = mn;
ans[x.S] = r[x.S] - l[x.S] + 1;
prev = x.S;
}
for(auto x : og){
cout<<ans[x.S]<<'\n';
}
}
Compilation message (stderr)
tra.cpp: In function 'int main()':
tra.cpp:105:30: warning: 'prev' may be used uninitialized in this function [-Wmaybe-uninitialized]
105 | if(mn == 1e9) mn = l[prev];
| ~~~~~~^
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |