답안 #469983

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
469983 2021-09-02T13:38:44 Z wind_reaper Traffic (CEOI11_tra) C++17
100 / 100
757 ms 59952 KB
#include <bits/stdc++.h>
/*
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
*/

using namespace std;
// using namespace __gnu_pbds;
using namespace chrono;

// mt19937 rng((int) std::chrono::steady_clock::now().time_since_epoch().count());
/*
template <class T> using ordered_set = tree <T, null_type, less <T>, rb_tree_tag, tree_order_statistics_node_update>;
*/

//***************** CONSTANTS *****************

const int MXN = 300001;

//***************** GLOBAL VARIABLES *****************

int N, M, A, B;
int tin[MXN], comp[MXN], L[MXN], R[MXN], pre[MXN], st[MXN], ptr;
int timer;
vector<int> g[MXN];
array<int, 3> p[MXN];

//***************** AUXILIARY STRUCTS *****************

int tarjan(int u){
	int low = tin[u] = ++timer;
	st[ptr++] = u;
	for(int v : g[u])
		if(!comp[v]) low = min(low, tin[v] ? : tarjan(v));

	if(tin[u] == low){
		for(int c = 0; c != u; ){
			comp[c = st[--ptr]] = u;
			for(int v : g[c]){
				L[u] = min(L[u], L[(comp[v] ? comp[v] : u) == u ? v : comp[v]]);
				R[u] = max(R[u], R[(comp[v] ? comp[v] : u) == u ? v : comp[v]]);
			}
		}
	}

	return low;
}

//***************** MAIN BODY *****************

void solve(){
	cin >> N >> M >> A >> B;

	memset(L, 0x3f, sizeof L);

	for(int i = 0; i < N; i++){
		cin >> p[i][1] >> p[i][0];
		p[i][2] = i + 1;
	}

	sort(p, p + N);

	for(int i = 0; i < N; i++)
		if(p[i][1] == A) L[p[i][2]] = R[p[i][2]] = i + 1;

	for(int i = 0; i < M; i++){
		int u, v, w;
		cin >> u >> v >> w;

		g[u].push_back(v);
		if(w > 1) g[v].push_back(u);
	}

	for(int i = 0; i < N; i++)
		if(!p[i][1] && !tin[p[i][2]]) tarjan(p[i][2]);

	for(int i = 0; i < N; i++)
		pre[i+1] = pre[i] + (p[i][1] == A && tin[p[i][2]]);

	for(int i = N - 1; i >= 0; --i){
		int j = comp[p[i][2]];
		if(!p[i][1])
			cout << (R[j] ? pre[R[j]] - pre[L[j]-1] : 0) << '\n';
	}
}

//***************** *****************

int32_t main(){
	ios_base::sync_with_stdio(NULL);
	cin.tie(NULL);

	#ifdef LOCAL
		auto begin = high_resolution_clock::now();
	#endif

	int tc = 1;
	// cin >> tc; 
	for (int t = 0; t < tc; t++)
		solve();

	#ifdef LOCAL 
		auto end = high_resolution_clock::now();
		cout << fixed << setprecision(4);
		cout << "Execution Time: " << duration_cast<duration<double>>(end - begin).count() << "seconds" << endl;
	#endif

	return 0;
}

/*
If code gives a WA, check for the following : 
1. I/O format

2. Are you clearing all global variables in between tests if multitests are a thing

3. Can you definitively prove the logic

4. If the code gives an inexplicable TLE, and you are sure you have the best possible complexity,
use faster io
*/
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 8524 KB Output is correct
2 Correct 5 ms 8532 KB Output is correct
3 Correct 5 ms 8524 KB Output is correct
4 Correct 6 ms 8524 KB Output is correct
5 Correct 6 ms 8576 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 8576 KB Output is correct
2 Correct 6 ms 8524 KB Output is correct
3 Correct 6 ms 8576 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 8524 KB Output is correct
2 Correct 6 ms 8524 KB Output is correct
3 Correct 6 ms 8524 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 8652 KB Output is correct
2 Correct 9 ms 8908 KB Output is correct
3 Correct 9 ms 8800 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 23 ms 9860 KB Output is correct
2 Correct 50 ms 13384 KB Output is correct
3 Correct 31 ms 10708 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 42 ms 10808 KB Output is correct
2 Correct 61 ms 15124 KB Output is correct
3 Correct 47 ms 12868 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 78 ms 12996 KB Output is correct
2 Correct 108 ms 19300 KB Output is correct
3 Correct 197 ms 18904 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 120 ms 14036 KB Output is correct
2 Correct 105 ms 19480 KB Output is correct
3 Correct 165 ms 19420 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 187 ms 17336 KB Output is correct
2 Correct 203 ms 26736 KB Output is correct
3 Correct 363 ms 28992 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 295 ms 22604 KB Output is correct
2 Correct 375 ms 37588 KB Output is correct
3 Correct 348 ms 30300 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 628 ms 28484 KB Output is correct
2 Correct 378 ms 39860 KB Output is correct
3 Correct 635 ms 43536 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 213 ms 19556 KB Output is correct
2 Correct 402 ms 42200 KB Output is correct
3 Correct 544 ms 39352 KB Output is correct
4 Correct 757 ms 59952 KB Output is correct