답안 #449359

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
449359 2021-08-02T05:56:37 Z ritul_kr_singh Traffic (CEOI11_tra) C++17
100 / 100
784 ms 49088 KB
#include <bits/stdc++.h>
using namespace std;
#define sp << ' ' <<
#define nl << '\n'

const int LIM = 3e5+1;

int n, m, A, B, dfsNum[LIM], id[LIM], L[LIM], R[LIM], pre[LIM], dfsTimer, st[LIM], stP;
vector<int> g[LIM], h[LIM];
array<int, 3> p[LIM];

int dfs(int u){
	int low = dfsNum[u] = ++dfsTimer;
	st[stP++] = u;
	for(int &v : g[u])
		if(id[v] < 0) low = min(low, dfsNum[v] ? : dfs(v));
	if(low == dfsNum[u]){
		for(int c=n; c!=u; ){
			id[c = st[--stP]] = u;
			for(int &v : g[c]){
				L[u] = min(L[u], L[id[v] < 0 || id[v] == u ? v : id[v]]);
				R[u] = max(R[u], R[id[v] < 0 || id[v] == u ? v : id[v]]);
			}
		}
	}
	return low;
}

signed main(){
	cin.tie(0)->sync_with_stdio(0);
	cin >> n >> m >> A >> B;

	fill(L, L+n, n+1);

	for(int i=0; i<n; ++i){
		auto &[x, y, j] = p[i];
		cin >> x >> y;
		j = i;
	}

	for(int i=0; i<m; ++i){
		int u, v, w;
		cin >> u >> v >> w; --u, --v;
		g[u].push_back(v);
		if(w > 1) g[v].push_back(u);
	}

	sort(p, p+n, [&](auto &x, auto &y){
		return x[1] < y[1];
	});
	
	for(int i=0; i<n; ++i){
		auto &[x, y, j] = p[i];
		if(x == A) L[j] = R[j] = i+1;
	}

	fill(id, id+n, -1);
	for(int u=0; u<n; ++u)
		if(!p[u][0] && !dfsNum[p[u][2]]) dfs(p[u][2]);

	for(int i=0; i<n; ++i){
		if(dfsNum[p[i][2]] && p[i][0] == A) ++pre[i+1];
		pre[i+1] += pre[i];
	}

	for(int i=n; --i>=0; ){
		int j = id[p[i][2]];
		if(!p[i][0])
			cout << (R[j] ? pre[R[j]] - pre[L[j]-1] : 0) nl;
	}
}
# 결과 실행 시간 메모리 Grader output
1 Correct 9 ms 14412 KB Output is correct
2 Correct 8 ms 14388 KB Output is correct
3 Correct 9 ms 14412 KB Output is correct
4 Correct 9 ms 14436 KB Output is correct
5 Correct 8 ms 14412 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 8 ms 14412 KB Output is correct
2 Correct 8 ms 14412 KB Output is correct
3 Correct 8 ms 14412 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 8 ms 14412 KB Output is correct
2 Correct 9 ms 14400 KB Output is correct
3 Correct 9 ms 14412 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 10 ms 14540 KB Output is correct
2 Correct 12 ms 14668 KB Output is correct
3 Correct 11 ms 14668 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 24 ms 15964 KB Output is correct
2 Correct 53 ms 17860 KB Output is correct
3 Correct 35 ms 15944 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 56 ms 17016 KB Output is correct
2 Correct 75 ms 19436 KB Output is correct
3 Correct 54 ms 17488 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 83 ms 19316 KB Output is correct
2 Correct 118 ms 22412 KB Output is correct
3 Correct 191 ms 20604 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 116 ms 20208 KB Output is correct
2 Correct 105 ms 22596 KB Output is correct
3 Correct 163 ms 20976 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 209 ms 23960 KB Output is correct
2 Correct 204 ms 27476 KB Output is correct
3 Correct 334 ms 26396 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 313 ms 29628 KB Output is correct
2 Correct 457 ms 34780 KB Output is correct
3 Correct 374 ms 27920 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 635 ms 35564 KB Output is correct
2 Correct 371 ms 36676 KB Output is correct
3 Correct 645 ms 33828 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 192 ms 26580 KB Output is correct
2 Correct 412 ms 38300 KB Output is correct
3 Correct 559 ms 32568 KB Output is correct
4 Correct 784 ms 49088 KB Output is correct