답안 #654275

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
654275 2022-10-30T20:17:54 Z fabijan_cikac Traffic (CEOI11_tra) C++17
100 / 100
886 ms 71072 KB
#include <bits/stdc++.h>

using namespace std;

#define pb push_back
#define pp pair<int, int>
#define F first
#define S second

struct point{
	int x, y, ix;
};

const int N = 3 * 1e5 + 100;

int n, m, A, B; vector<point> pt;
vector<int> g[N], tg[N], graph[N], order;
int new_idx[N], root[N], used[N], l[N], r[N];
int w[N], pref[N];

bool cmp(point x, point y){
	if (x.x != y.x)
		return (x.x < y.x);
	return (x.y > y.y);
}

void dfs1(int x){
	used[x] = 1;
	for (int y: g[x]){
		if (!used[y]) dfs1(y);
	}
	order.pb(x);
}

int cnt = 0;
void dfs2(int x){
	used[x] = 1;
	for (int y: tg[x]){
		if (!used[y]) dfs2(y);
	}
	root[x] = cnt;
	if (pt[x].x == A){
		l[cnt] = min(l[cnt], x);
		r[cnt] = max(r[cnt], x);
	}
}

void dfs3(int x){
	used[x] = 1;
	for (int y: graph[x]){
		if (!used[y]) dfs3(y);
		l[x] = min(l[x], l[y]);
		r[x] = max(r[x], r[y]);
	}
}

int main(){
	ios_base::sync_with_stdio(0);
	cin.tie(0); cout.tie(0);
	
	cin >> n >> m >> A >> B;
	pt.resize(n); int k = 1;
	for (int i = 0; i < n; ++i){
		cin >> pt[i].x >> pt[i].y;
		pt[i].ix = i;
	}
	sort(pt.begin(), pt.end(), cmp);
	for (auto i = 0; i < n; ++i){
		new_idx[pt[i].ix] = i;
		l[i] = N; r[i] = -1;
		if (pt[i].x == A) ++w[i];
	}
	for (int i = 0; i < m; ++i){
		int u, v, t; cin >> u >> v >> t;
		--u; --v; u = new_idx[u]; v = new_idx[v];
		g[u].pb(v); tg[v].pb(u);
		if (t == 2){
			g[v].pb(u); tg[u].pb(v);
		}
	}
	while (k < n && pt[k].x == 0) ++k;
	for (int i = 0; i < k; ++i){
		if (!used[i]) dfs1(i);
	}
	for (int i = 0; i < n; ++i){
		if (pt[i].x == A && !used[i]) --w[i];
	}
	memset(used, 0, sizeof(used));
	reverse(order.begin(), order.end());
	for (int x: order){
		if (!used[x]){
			dfs2(x); ++cnt;
		}
	}
	for (int i = 0; i < n; ++i){
		for (int x: g[i]) graph[root[i]].pb(root[x]);
	}
	memset(used, 0, sizeof(used));
	for (int i = 0; i < cnt; ++i){
		if (!used[i]) dfs3(i);
	}
	pref[0] = w[0];
	for (int i = 1; i < n; ++i)
		pref[i] = w[i] + pref[i - 1];
	for (int i = 0; i < k; ++i){
		int x = root[i];
		cout << (pref[r[x]] - pref[l[x] - 1]) << '\n';
	}
	
	
	return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 12 ms 22612 KB Output is correct
2 Correct 16 ms 22664 KB Output is correct
3 Correct 15 ms 22568 KB Output is correct
4 Correct 12 ms 22612 KB Output is correct
5 Correct 13 ms 22616 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 13 ms 22668 KB Output is correct
2 Correct 12 ms 22612 KB Output is correct
3 Correct 13 ms 22612 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 11 ms 22620 KB Output is correct
2 Correct 12 ms 22772 KB Output is correct
3 Correct 12 ms 22740 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 13 ms 22868 KB Output is correct
2 Correct 20 ms 23312 KB Output is correct
3 Correct 15 ms 23152 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 27 ms 24808 KB Output is correct
2 Correct 61 ms 29984 KB Output is correct
3 Correct 40 ms 26424 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 60 ms 27280 KB Output is correct
2 Correct 93 ms 32316 KB Output is correct
3 Correct 57 ms 30080 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 108 ms 31344 KB Output is correct
2 Correct 129 ms 39300 KB Output is correct
3 Correct 231 ms 38032 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 171 ms 33524 KB Output is correct
2 Correct 144 ms 38888 KB Output is correct
3 Correct 223 ms 38656 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 260 ms 39596 KB Output is correct
2 Correct 236 ms 47972 KB Output is correct
3 Correct 484 ms 48804 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 370 ms 49556 KB Output is correct
2 Correct 427 ms 60416 KB Output is correct
3 Correct 441 ms 52056 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 873 ms 63380 KB Output is correct
2 Correct 426 ms 62664 KB Output is correct
3 Correct 812 ms 59812 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 201 ms 41112 KB Output is correct
2 Correct 514 ms 67360 KB Output is correct
3 Correct 661 ms 61532 KB Output is correct
4 Correct 886 ms 71072 KB Output is correct