120842024-12-01 17:23:13RRoliA lehető legkevesebb átszállás (50 pont)cpp17Wrong answer 49/509ms1116 KiB
#include <bits/stdc++.h>
using namespace std;

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

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 = 1; i <= m && !joe; i++) {
		if(i > ugras) {
			if(max_ert == 0) {
				cout << -1;
				joe = true;
			}
			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];
		}
	}
    if(!joe) {
    	cout << sz << '\n';
		for(int i = 0; i <= sz; i++) cout << ki[i] << ' '; 
    }

	return 0;
}
SubtaskSumTestVerdictTimeMemory
base49/50
1Accepted0/01ms320 KiB
2Accepted0/09ms1080 KiB
3Wrong answer0/11ms320 KiB
4Accepted1/11ms508 KiB
5Accepted2/21ms320 KiB
6Accepted2/21ms320 KiB
7Accepted2/22ms320 KiB
8Accepted2/22ms320 KiB
9Accepted2/22ms320 KiB
10Accepted2/23ms320 KiB
11Accepted2/24ms568 KiB
12Accepted2/24ms568 KiB
13Accepted2/22ms568 KiB
14Accepted2/23ms572 KiB
15Accepted2/24ms568 KiB
16Accepted2/24ms696 KiB
17Accepted2/27ms884 KiB
18Accepted2/28ms1084 KiB
19Accepted2/28ms1080 KiB
20Accepted2/28ms1080 KiB
21Accepted2/28ms1116 KiB
22Accepted2/28ms1080 KiB
23Accepted2/28ms320 KiB
24Accepted2/28ms508 KiB
25Accepted2/28ms320 KiB
26Accepted2/28ms416 KiB
27Accepted2/28ms320 KiB
28Accepted2/28ms500 KiB