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>
using namespace std;
const int INF = 2'000'000'000;
const int MXN = 300'000;
vector<int> g[MXN];
int X[MXN], Y[MXN], ord[MXN], D[2][MXN];
vector<int> pref, west, east;
vector<bool> vis(MXN);
void dfs(int node){
if(vis[node])
return;
vis[node] = 1;
if(ord[node] != -1){
D[0][node] = min(D[0][node], ord[node]);
D[1][node] = max(D[1][node], ord[node]);
}
for(int v : g[node]){
dfs(v);
}
for(int v : g[node]){
D[0][node] = min(D[0][node], D[0][v]);
D[1][node] = max(D[1][node], D[1][v]);
}
}
int32_t main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int N, M, A, B;
cin >> N >> M >> A >> B;
memset(ord, -1, sizeof ord);
memset(D[1], -1, sizeof D[1]);
for(int i = 0; i < N; i++)
D[0][i] = INF;
for(int i = 0; i < N; i++){
cin >> X[i] >> Y[i];
if(X[i] == 0) west.push_back(i);
else if (X[i] == A) east.push_back(i);
}
for(int i = 0; i < M; i++){
int u, v, k;
cin >> u >> v >> k;
--u, --v;
g[u].push_back(v);
if(k == 2) g[v].push_back(u);
}
sort(west.begin(), west.end(), [&](int i, int j){
return Y[i] > Y[j];
});
sort(east.begin(), east.end(), [&](int i, int j){
return Y[i] < Y[j];
});
for(int i = 0; i < east.size(); i++)
ord[east[i]] = i;
reverse(west.begin(), west.end());
for(int v : west){
dfs(v);
}
int x = east.size();
pref.resize(x+1);
for(int i = 1; i <= x; i++)
pref[i] = pref[i-1] + vis[east[i-1]];
fill(vis.begin(), vis.end(), 0);
for(int v : west)
dfs(v);
fill(vis.begin(), vis.end(), 0);
reverse(west.begin(), west.end());
for(int v : west)
dfs(v);
for(int v : west){
if(D[1][v] == -1){
cout << 0 << '\n';
continue;
}
cout << pref[D[1][v]+1] - pref[D[0][v]] << '\n';
}
return 0;
}
Compilation message (stderr)
tra.cpp: In function 'int32_t main()':
tra.cpp:69:19: 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 < east.size(); i++)
| ~~^~~~~~~~~~~~~
# | 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... |