62242023-11-08 11:46:57CWMZsonglőrködéscpp17Time limit exceeded 35/1001.587s63024 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, unordered_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,unordered_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
1Accepted3ms1808 KiB
2Accepted3ms2064 KiB
subtask20/20
3Accepted115ms3520 KiB
4Time limit exceeded1.587s19556 KiB
5Time limit exceeded1.572s45412 KiB
6Time limit exceeded1.572s55328 KiB
7Time limit exceeded1.557s61280 KiB
8Time limit exceeded1.557s61428 KiB
9Time limit exceeded1.577s61568 KiB
10Time limit exceeded1.554s61976 KiB
11Time limit exceeded1.582s62032 KiB
subtask335/35
12Accepted3ms3428 KiB
13Accepted3ms3436 KiB
14Accepted4ms3736 KiB
15Accepted3ms3664 KiB
16Accepted6ms3956 KiB
17Accepted9ms4276 KiB
18Accepted6ms4076 KiB
19Accepted10ms4584 KiB
20Accepted10ms4780 KiB
subtask40/45
21Accepted115ms5540 KiB
22Time limit exceeded1.572s6944 KiB
23Time limit exceeded1.539s47320 KiB
24Time limit exceeded1.57s12708 KiB
25Time limit exceeded1.577s62764 KiB
26Time limit exceeded1.57s13776 KiB
27Time limit exceeded1.565s63024 KiB
28Time limit exceeded1.562s13868 KiB
29Time limit exceeded1.557s62780 KiB