Submission #651468

# Submission time Handle Problem Language Result Execution time Memory
651468 2022-10-18T22:24:20 Z Markomafko972 Traffic (CEOI11_tra) C++14
16 / 100
5000 ms 70744 KB
#include <bits/stdc++.h>
#define X first
#define Y second
#define pb push_back
#define pii pair<int, int>
typedef long long ll;
using namespace std;

const int MOD = 1e9 + 7;
const ll INF = 1e18;
const int OFF = (1 << 20);

int n, m, a, b, px, py, poc, kr, ty;
vector<int> v[300005];
vector<int> vr[300005];
int bio[300005];
stack<int> st;
int tren;
int comp[300005];
vector<int> e[300005];
vector< pair<int, int> > l;
vector< pair<int, int> > r;
vector< pair<int, int> > r2;
pair<int, int> kol[300005];
pair<int, int> dp[300005];
int z;
int dosao[300005];

void prolaz(int x) {
	dosao[x] = 1;
	
	for (int i = 0; i < e[x].size(); i++) {
		if (dosao[e[x][i]] == 0) prolaz(e[x][i]);
	}
}

void dfs(int x) {
	bio[x] = 1;
	
	for (int i = 0; i < v[x].size(); i++) {
		if (bio[v[x][i]] == 0) {
			dfs(v[x][i]);
		}
	}
	
	st.push(x);
}

void dfsr(int x) {
	comp[x] = tren;
	//cout << x << " je " << tren << endl;
	
	for (int i = 0; i < vr[x].size(); i++) {
		if (comp[vr[x][i]] == -1) dfsr(vr[x][i]);
	}
}

pair<int, int> rek(int x) {
	if (dp[x] != make_pair((int)1e9, (int)-1e9)) return dp[x];
	
	pair<int, int> &ret = dp[x];
	ret = kol[x];
	
	for (int i = 0; i < e[x].size(); i++) {
		pair<int, int> sus = rek(e[x][i]);
		ret.X = min(ret.X, sus.X);
		ret.Y = max(ret.Y, sus.Y);
	}
	
	return ret;
}

int main () {

	ios_base::sync_with_stdio(false);
	cin.tie(0);
	
	cin >> n >> m >> a >> b;
	for (int i = 0; i < n; i++) {
		cin >> px >> py;
		if (px == 0) l.push_back({py, i});
		if (px == a) r.push_back({py, i});
	}
	
	for (int i = 0; i < m; i++) {
		cin >> poc >> kr >> ty;
		poc--;
		kr--;
		if (ty == 1) {
			v[poc].push_back(kr);
			vr[kr].push_back(poc);
		}
		else {
			v[poc].push_back(kr);
			v[kr].push_back(poc);
			vr[poc].push_back(kr);
			vr[kr].push_back(poc);
		}
	}
	
	for (int i = 0; i < n; i++) {
		if (bio[i] == 0) {
			dfs(i);
		}
	}
	
	memset(comp, -1, sizeof comp);
	while (st.size() > 0) {
		if (comp[st.top()] != -1) {
			st.pop();
			continue;
		}
		dfsr(st.top());
		st.pop();
		tren++;
	}
	
	for (int i = 0; i < n; i++) {
		dp[i] = {1e9, -1e9};
		kol[i] = {1e9, -1e9};
		for (int j = 0; j < v[i].size(); j++) {
			if (comp[i] != comp[v[i][j]]) e[comp[i]].push_back(comp[v[i][j]]);
		}
	}
	
	for (int i = 0; i < l.size(); i++) {
		prolaz(comp[l[i].Y]);
	}
	
	for (int i = 0; i < r.size(); i++) {
		if (dosao[comp[r[i].Y]] == 1) r2.push_back(r[i]);
	}
	r = r2;
	
	sort(r.begin(), r.end());
	kol[comp[r[0].Y]] = {0, 0};
	int novi = 1;
	for (int i = 1; i < r.size(); i++) {
		if (comp[r[i-1].Y] == comp[r[i].Y]) {
			kol[comp[r[i].Y]].Y = novi;
			novi++;
		}
		else {
			kol[comp[r[i].Y]] = {novi, novi};
			novi++;
		}
	}
	
	/*for (int i = 0; i < tren; i++) {
		cout << i << ": " << kol[i].X << " " << kol[i].Y << endl;
	}*/
	
	sort(l.begin(), l.end());
	for (int i = (int)l.size()-1; i >= 0; i--) {
		pair<int, int> rj = rek(comp[l[i].Y]);
		if (rj == make_pair((int)1e9, (int)-1e9)) cout << 0 << endl;
		else cout << rj.Y-rj.X+1 << endl;
	}

	return 0;
}

Compilation message

tra.cpp: In function 'void prolaz(int)':
tra.cpp:32:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   32 |  for (int i = 0; i < e[x].size(); i++) {
      |                  ~~^~~~~~~~~~~~~
tra.cpp: In function 'void dfs(int)':
tra.cpp:40:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   40 |  for (int i = 0; i < v[x].size(); i++) {
      |                  ~~^~~~~~~~~~~~~
tra.cpp: In function 'void dfsr(int)':
tra.cpp:53:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   53 |  for (int i = 0; i < vr[x].size(); i++) {
      |                  ~~^~~~~~~~~~~~~~
tra.cpp: In function 'std::pair<int, int> rek(int)':
tra.cpp:64:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   64 |  for (int i = 0; i < e[x].size(); i++) {
      |                  ~~^~~~~~~~~~~~~
tra.cpp: In function 'int main()':
tra.cpp:121:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  121 |   for (int j = 0; j < v[i].size(); j++) {
      |                   ~~^~~~~~~~~~~~~
tra.cpp:126:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  126 |  for (int i = 0; i < l.size(); i++) {
      |                  ~~^~~~~~~~~~
tra.cpp:130:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  130 |  for (int i = 0; i < r.size(); i++) {
      |                  ~~^~~~~~~~~~
tra.cpp:138:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  138 |  for (int i = 1; i < r.size(); i++) {
      |                  ~~^~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Incorrect 13 ms 22612 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 12 ms 22612 KB Output is correct
2 Correct 12 ms 22632 KB Output is correct
3 Correct 12 ms 22596 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 12 ms 22660 KB Output is correct
2 Correct 12 ms 22740 KB Output is correct
3 Correct 13 ms 22640 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 14 ms 22792 KB Output is correct
2 Correct 19 ms 23284 KB Output is correct
3 Execution timed out 5055 ms 23028 KB Time limit exceeded
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 29 ms 24780 KB Output is correct
2 Incorrect 96 ms 29484 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 45 ms 27452 KB Output is correct
2 Correct 104 ms 31204 KB Output is correct
3 Execution timed out 5075 ms 29516 KB Time limit exceeded
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 96 ms 32408 KB Output is correct
2 Correct 190 ms 38660 KB Output is correct
3 Execution timed out 5039 ms 37064 KB Time limit exceeded
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 162 ms 34424 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 265 ms 42264 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 352 ms 54416 KB Output is correct
2 Incorrect 532 ms 65276 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 811 ms 68084 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 228 ms 45768 KB Output is correct
2 Incorrect 611 ms 70744 KB Output isn't correct
3 Halted 0 ms 0 KB -