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 <iostream>
#include <vector>
#include <set>
#include <map>
#include <queue>
using namespace std;
typedef pair<int, int> pi;
const int MAXN = 300000;
int N, M;
vector<int> adj[MAXN + 1];
vector<int> rev[MAXN + 1]; // reverse edges
int xy[MAXN + 5][2];
bool inGraph[MAXN + 5]; // can be reached from any of the west
void dfs1(int x) {
inGraph[x] = true;
for (int c : adj[x]) {
if (!inGraph[c]) {
dfs1(c);
}
}
}
set<pi> east; // sort east coords top to bot
set<pi> west; // sort east coords top to bot
int eID[MAXN + 5];
bool visited[MAXN + 5];
int top[MAXN + 5]; // highest east it can reach, lower ID
int bot[MAXN + 5]; // lowest east it can reach, higher ID
queue<int> Q; // bfs
int main() {
int A, B;
cin >> N >> M >> A >> B;
for (int i = 1; i <= N; i++) {
cin >> xy[i][0] >> xy[i][1];
}
for (int m = 0; m < M; m++) {
int a, b, k;
cin >> a >> b >> k;
adj[a].push_back(b);
rev[b].push_back(a);
if (k == 2) {
adj[b].push_back(a);
rev[a].push_back(b);
}
}
for (int i = 1; i <= N; i++) {
if (xy[i][0] == 0) {
dfs1(i);
}
}
for (int i = 1; i <= N; i++) {
if (xy[i][0] == A) {
if (inGraph[i]) east.insert({ -xy[i][1], i });
}
}
int count = 0;
fill(top, top + MAXN, MAXN + 1);
fill(bot, bot + MAXN, -MAXN-1);
for (auto e : east) {
eID[e.second] = count++;
top[e.second] = eID[e.second];
bot[e.second] = eID[e.second];
Q.push(e.second);
}
while (!Q.empty()) {
int curr = Q.front(); Q.pop();
for (int c : rev[curr]) {
if (top[c] <= top[curr] && bot[c] >= bot[curr])continue;
top[c] = min(top[c], top[curr]);
bot[c] = max(bot[c], bot[curr]);
Q.push(c);
}
}
for (int i = 1; i <= N; i++) {
if (xy[i][0] == 0) {
if (bot[i] != -MAXN - 1 && top[i] != MAXN + 1) west.insert({ -xy[i][1], bot[i] - top[i] + 1 });
else west.insert({-xy[i][1], 0});
}
}
for (auto e : west) {
//cout << e.second << endl;
}
}
Compilation message (stderr)
tra.cpp: In function 'int main()':
tra.cpp:84:12: warning: variable 'e' set but not used [-Wunused-but-set-variable]
84 | for (auto e : west) {
| ^
# | 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... |