62232023-11-08 11:43:38CWMZsonglőrködéscpp17Time limit exceeded 35/1001.6s40860 KiB
// KKGyak.cpp : This file contains the 'main' function. Program execution begins and ends there.
//
using namespace std;

#include <iostream>
#include <map>
#include <set>
#include <unordered_set>

int main()
{
    int a;
    cin >> a;
	map<int, multiset<int>> dataStr;
	unordered_set<int> exists;
	for (size_t i = 0; i < a; i++)
	{
		int a, b;
		cin >> a >> b;
		if (exists.count(a) == 0) {
			dataStr.insert({ a,multiset<int>() });
			exists.insert(a);
		}
		dataStr[a].insert(b);
	}
	int res = 0;
	while (true)
	{
		int chain = -1;
		for (auto m : dataStr) {
			if (m.second.size() > 0) {
				chain = *m.second.begin();
				dataStr[m.first].erase(dataStr[m.first].begin());
				break;
			}
		}
		if (chain == -1) break;
		while (true)
		{
			if (exists.count(chain) == 1 && dataStr[chain].size()>0) {
				int old = chain;
				chain = *dataStr[chain].begin();
				dataStr[old].erase(dataStr[old].begin());
			}
			else break;
		}
		res++;
	}
	cout << res;
}

// Run program: Ctrl + F5 or Debug > Start Without Debugging menu
// Debug program: F5 or Debug > Start Debugging menu

// Tips for Getting Started: 
//   1. Use the Solution Explorer window to add/manage files
//   2. Use the Team Explorer window to connect to source control
//   3. Use the Output window to see build output and other messages
//   4. Use the Error List window to view errors
//   5. Go to Project > Add New Item to create new code files, or Project > Add Existing Item to add existing code files to the project
//   6. In the future, to open this project again, go to File > Open > Project and select the .sln file
SubtaskSumTestVerdictTimeMemory
subtask10/0
1Accepted3ms1816 KiB
2Accepted3ms2060 KiB
subtask20/20
3Accepted32ms2764 KiB
4Time limit exceeded1.6s12572 KiB
5Time limit exceeded1.575s28880 KiB
6Time limit exceeded1.572s35740 KiB
7Time limit exceeded1.57s39236 KiB
8Time limit exceeded1.56s39536 KiB
9Time limit exceeded1.532s39412 KiB
10Time limit exceeded1.577s39728 KiB
11Time limit exceeded1.569s39928 KiB
subtask335/35
12Accepted3ms3684 KiB
13Accepted3ms3800 KiB
14Accepted3ms3852 KiB
15Accepted3ms3828 KiB
16Accepted4ms4224 KiB
17Accepted4ms4208 KiB
18Accepted4ms4000 KiB
19Accepted4ms4164 KiB
20Accepted4ms4276 KiB
subtask40/45
21Accepted32ms4652 KiB
22Time limit exceeded1.574s6632 KiB
23Time limit exceeded1.575s30376 KiB
24Time limit exceeded1.562s13364 KiB
25Time limit exceeded1.552s40668 KiB
26Time limit exceeded1.547s14660 KiB
27Time limit exceeded1.575s40508 KiB
28Time limit exceeded1.574s14860 KiB
29Time limit exceeded1.557s40860 KiB