Submission #395063

# Submission time Handle Problem Language Result Execution time Memory
395063 2021-04-27T16:59:42 Z wind_reaper Traffic (CEOI11_tra) C++17
24 / 100
657 ms 39880 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 8 ms 9676 KB Output is correct
2 Correct 7 ms 9708 KB Output is correct
3 Correct 7 ms 9676 KB Output is correct
4 Correct 7 ms 9712 KB Output is correct
5 Correct 7 ms 9676 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 7 ms 9712 KB Output is correct
2 Correct 7 ms 9676 KB Output is correct
3 Correct 7 ms 9676 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 7 ms 9676 KB Output is correct
2 Incorrect 7 ms 9804 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 11 ms 10060 KB Output is correct
3 Correct 10 ms 9980 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 18 ms 10956 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 43 ms 12508 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 78 ms 15112 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 135 ms 17144 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 203 ms 21416 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 337 ms 28104 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 657 ms 39880 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 171 ms 23512 KB Output isn't correct
2 Halted 0 ms 0 KB -