# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
682122 |
2023-01-15T20:50:25 Z |
as111 |
Traffic (CEOI11_tra) |
C++14 |
|
1127 ms |
44708 KB |
#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);
visited[e.second] = true;
}
while (!Q.empty()) {
int curr = Q.front(); Q.pop();
for (int c : rev[curr]) {
//if (top[c] <= top[curr] && bot[c] >= bot[curr])continue;
if (visited[c]) continue;
visited[c] = true;
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;
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
8 ms |
16724 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
8 ms |
16724 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
10 ms |
16712 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
11 ms |
16784 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
33 ms |
17732 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
82 ms |
19568 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
165 ms |
22044 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
237 ms |
23724 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
379 ms |
27316 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
547 ms |
33236 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1127 ms |
44708 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
408 ms |
27324 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |