Submission #774327

# Submission time Handle Problem Language Result Execution time Memory
774327 2023-07-05T14:49:00 Z NK_ Traffic (CEOI11_tra) C++17
8 / 100
398 ms 50984 KB
// Success consists of going from failure to failure without loss of enthusiasm
#include <bits/stdc++.h>

using namespace std;

#define nl '\n'
#define f first
#define s second
#define mp make_pair

#define pb push_back

using pi = pair<int, int>;
template<class T> using V = vector<T>;

int main() {
	cin.tie(0)->sync_with_stdio(0);
	
	int N, M, A, B; cin >> N >> M >> A >> B;

	V<pi> P(N); for(auto& x : P) cin >> x.f >> x.s;

	V<V<int>> adj(N);

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

		adj[u].pb(v);
		if (d) adj[v].pb(u);
	}

	V<int> low(N), disc(N), comp(N, -1), st, comps;

	int t = 0;
	function<int(int)> dfs = [&](int u) {
		st.pb(u);
		low[u] = disc[u] = ++t;

		for(auto& v : adj[u]) {
			if (comp[v] == -1) low[u] = min(low[u], disc[v] ?: dfs(v));
		}

		if (low[u] == disc[u]) {
			comps.pb(u);
			for(int v = -1; v != u; ) comp[v = st.back()] = u, st.pop_back();
		}	

		return low[u];
	};

	for(int i = 0; i < N; i++) if (!disc[i]) dfs(i);
	// for(int i = 0; i < N; i++) {
		// cout << i << " " << comp[i] << endl;
	// }
	// for(auto x : comps) cout << x << " ";
	// cout << endl;
	// reverse(begin(comps), end(comps));


	V<V<int>> C(N); V<int> E(N, 0), W; 
	for(int i = 0; i < N; i++) {
		C[comp[i]].pb(i);
		if (P[i].f == A) E[comp[i]]++;
		if (P[i].f == 0) W.pb(i);
	}

	sort(begin(W), end(W), [&](int x, int y) {
		return P[x].s > P[y].s;
	});

	V<int> PAR(N); iota(begin(PAR), end(PAR), 0);
	function<int(int)> get = [&](int u) { return PAR[u] == u ? u : PAR[u] = get(PAR[u]); };

	for(auto c : comps) {
		// cout << "C: " << c << " " << E[c] << endl;
		set<int> seen = {c};
		for(auto u : C[c]) for(auto v : adj[u]) {
			int cv = comp[v];
			if (seen.insert(cv).second) {
				// cout << u << " -> " << c << " " << comp[v] << endl;
				if (get(c) != get(cv)) {
					PAR[cv] = c;
					E[c] += E[cv]; 
				}
			}
		}
	}
	
	for(auto u : W) cout << E[comp[u]] << nl;

    return 0;
}


# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 320 KB Output is correct
3 Correct 1 ms 320 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 324 KB Output is correct
2 Incorrect 1 ms 212 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 316 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 724 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 12 ms 5364 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 26 ms 7472 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 58 ms 14976 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 72 ms 15676 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 163 ms 27840 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 294 ms 46012 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 398 ms 50984 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 200 ms 43044 KB Output isn't correct
2 Halted 0 ms 0 KB -