120752024-11-29 13:14:59RRoliA lehető legkevesebb átszállás (50 pont)cpp17Wrong answer 49/509ms1188 KiB
#include <bits/stdc++.h>
using namespace std;

int n, m, a[100001][2], ki[100001];

int main() {
	cin >> n >> m;
	for(int i = 1; i <= m; i++) {
		int e, u;
		cin >> e >> u;
		if(a[e][0] < u) {
			a[e][0] = u;
			a[e][1] = i;
		}
	}

	int sz = 0, ugras = a[1][0], max_ert = 0, max_ind = 0;
	ki[0] = a[1][1];
	for(int i = 2; i <= m; i++) {
		if(i > ugras) {
			if(max_ert == 0) {
				cout << -1;
				return 0;
			}
			sz++;
			ki[sz] = max_ind;
			ugras = max_ert;
			max_ert = 0;
		}
		if(a[i][0] > max_ert) {
			max_ert = a[i][0];
			max_ind = a[i][1];
		}
	}
	cout << sz << '\n';
	for(int i = 0; i <= sz; i++) cout << ki[i] << ' ';


	return 0;
}
SubtaskSumTestVerdictTimeMemory
base49/50
1Accepted0/01ms320 KiB
2Accepted0/09ms1132 KiB
3Wrong answer0/11ms320 KiB
4Accepted1/11ms336 KiB
5Accepted2/21ms320 KiB
6Accepted2/21ms320 KiB
7Accepted2/22ms396 KiB
8Accepted2/22ms404 KiB
9Accepted2/22ms432 KiB
10Accepted2/23ms320 KiB
11Accepted2/24ms520 KiB
12Accepted2/24ms580 KiB
13Accepted2/22ms500 KiB
14Accepted2/23ms568 KiB
15Accepted2/24ms712 KiB
16Accepted2/24ms568 KiB
17Accepted2/28ms1088 KiB
18Accepted2/28ms1084 KiB
19Accepted2/28ms1040 KiB
20Accepted2/28ms1188 KiB
21Accepted2/28ms988 KiB
22Accepted2/29ms1080 KiB
23Accepted2/28ms500 KiB
24Accepted2/28ms616 KiB
25Accepted2/28ms472 KiB
26Accepted2/28ms540 KiB
27Accepted2/28ms456 KiB
28Accepted2/28ms536 KiB