Submission #395074

# Submission time Handle Problem Language Result Execution time Memory
395074 2021-04-27T17:16:50 Z wind_reaper Traffic (CEOI11_tra) C++17
8 / 100
677 ms 24952 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);

void dfs(int node){
	if(vis[node])
		return;

	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]){
		dfs(v);
	}

	for(int v : g[node]){
		D[0][node] = min(D[0][node], D[0][v]);
		D[1][node] = max(D[1][node], D[1][v]);
	}
}

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);	
	}

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

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

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

	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 9676 KB Output is correct
3 Correct 8 ms 9668 KB Output is correct
4 Correct 7 ms 9716 KB Output is correct
5 Correct 7 ms 9676 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 7 ms 9676 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 7 ms 9668 KB Output is correct
2 Incorrect 7 ms 9676 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 8 ms 9860 KB Output is correct
2 Incorrect 10 ms 10028 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 18 ms 10492 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 38 ms 11292 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 64 ms 12740 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 110 ms 13584 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 184 ms 15748 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 310 ms 19164 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 677 ms 24952 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 166 ms 16320 KB Output isn't correct
2 Halted 0 ms 0 KB -