Submission #395064

# Submission time Handle Problem Language Result Execution time Memory
395064 2021-04-27T17:00:07 Z wind_reaper Traffic (CEOI11_tra) C++17
24 / 100
663 ms 25068 KB
#include <bits/stdc++.h>

using namespace std;

const int INF = 2'000'000'000;
const int MXN = 300'000;

vector<int> g[MXN];
int X[MXN], Y[MXN], ord[MXN], D[2][MXN];
vector<int> pref, west, east;
vector<bool> vis(MXN);

pair<int, int> dfs(int node){
	if(vis[node])
		return {D[0][node], D[1][node]};
	
	vis[node] = 1;

	if(ord[node] != -1){
		D[0][node] = min(D[0][node], ord[node]);
		D[1][node] = max(D[1][node], ord[node]);
	}

	for(int v : g[node]){
		pair<int, int> R = dfs(v);
		D[0][node] = min(D[0][node], R.first);
		D[1][node] = max(D[1][node], R.second);
	}

	
	return {D[0][node], D[1][node]};
}

int32_t main(){
	ios_base::sync_with_stdio(false); 
	cin.tie(NULL); 
	
	int N, M, A, B;
	cin >> N >> M >> A >> B;

	memset(ord, -1, sizeof ord);
	memset(D[1], -1, sizeof D[1]);

	for(int i = 0; i < N; i++)
		D[0][i] = INF;

	for(int i = 0; i < N; i++){
		cin >> X[i] >> Y[i];
		if(X[i] == 0) west.push_back(i);
		else if (X[i] == A) east.push_back(i);
	}

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

	sort(west.begin(), west.end(), [&](int i, int j){
		return Y[i] > Y[j];
	});

	sort(east.begin(), east.end(), [&](int i, int j){
		return Y[i] > Y[j];
	});

	for(int i = 0; i < east.size(); i++)
		ord[east[i]] = i;

	for(int v : west){
		dfs(v);	
	}

	for(int i = 0; i < N; i++){
		for(int v : g[i]){
			D[0][i] = min(D[0][i], D[0][v]);
			D[1][i] = max(D[1][i], D[1][v]);
		}
	}

	fill(vis.begin(), vis.end(), 0);

	for(int v : west)
		dfs(v);

	int x = east.size();
	
	pref.resize(x+1);
	for(int i = 1; i <= x; i++)
		pref[i] = pref[i-1] + vis[east[i-1]];

	for(int v : west){
		if(D[1][v] == -1){
			cout << 0 << '\n';
			continue;
		}

		cout << pref[D[1][v]+1] - pref[D[0][v]] << '\n';
	}

	return 0; 
}

Compilation message

tra.cpp: In function 'int32_t main()':
tra.cpp:69:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   69 |  for(int i = 0; i < east.size(); i++)
      |                 ~~^~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 7 ms 9680 KB Output is correct
2 Correct 7 ms 9732 KB Output is correct
3 Correct 7 ms 9768 KB Output is correct
4 Correct 7 ms 9676 KB Output is correct
5 Correct 7 ms 9676 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 7 ms 9768 KB Output is correct
2 Correct 7 ms 9724 KB Output is correct
3 Correct 7 ms 9676 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 8 ms 9768 KB Output is correct
2 Incorrect 7 ms 9792 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 8 ms 9804 KB Output is correct
2 Correct 10 ms 9932 KB Output is correct
3 Correct 10 ms 9804 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 20 ms 10444 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 39 ms 11332 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 67 ms 12664 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 117 ms 13652 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 177 ms 15756 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 326 ms 19140 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 663 ms 25068 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 165 ms 16320 KB Output isn't correct
2 Halted 0 ms 0 KB -