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 pii pair<int, int>
using namespace std;
const int MAX = 300003;
int X[MAX], Y[MAX], U[MAX], D[MAX];
bool V[MAX];
vector<int> G[MAX], RG[MAX];
void BFS(int* S, int st, int C) {
S[st] = C;
queue<int> Q;
Q.push(st);
while (!Q.empty()) {
int cur = Q.front(); Q.pop();
for (int next : RG[cur]) {
if (S[next] != -1) continue;
S[next] = C;
Q.push(next);
}
}
}
int main() {
ios::sync_with_stdio(0); cin.tie(0);
int N, M, A, B;
cin >> N >> M >> A >> B;
for (int i = 1; i <= N; ++i) cin >> X[i] >> Y[i];
for (int i = 0; i < M; ++i) {
int a, b, c;
cin >> a >> b >> c;
G[a].push_back(b);
RG[b].push_back(a);
if (c == 2) {
G[b].push_back(a);
RG[a].push_back(b);
}
}
vector<pii> L, R;
for (int i = 1; i <= N; ++i) {
if (X[i] == 0) L.emplace_back(Y[i], i);
}
sort(L.begin(), L.end(), greater<pii>());
queue<int> Q;
for (auto [_, n] : L) {
V[n] = 1;
Q.push(n);
}
while (!Q.empty()) {
int cur = Q.front(); Q.pop();
for (int next : G[cur]) {
if (V[next]) continue;
V[next] = 1;
Q.push(next);
}
}
for (int i = 1; i <= N; ++i) {
if (X[i] == A && V[i]) R.emplace_back(Y[i], i);
}
sort(R.begin(), R.end(), greater<pii>());
memset(U, 0xff, sizeof(U));
memset(D, 0xff, sizeof(D));
for (int i = 0; i < R.size(); ++i) {
auto [_, n] = R[i];
BFS(U, n, i);
}
for (int i = R.size() - 1; i >= 0; --i) {
auto [_, n] = R[i];
BFS(D, n, i);
}
for (auto [_, n] : L) {
int ans = (D[n] == -1 ? 0 : D[n] - U[n] + 1);
cout << ans << '\n';
}
return 0;
}
Compilation message (stderr)
tra.cpp: In function 'int main()':
tra.cpp:66:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
66 | for (int i = 0; i < R.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... |