62212023-11-08 11:33:27CWMZsonglőrködéscpp17Time limit exceeded 0/1001.6s40828 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, set<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,set<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(chain);
				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(chain);
			}
			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
2Accepted3ms2008 KiB
subtask20/20
3Accepted32ms2992 KiB
4Time limit exceeded1.6s12740 KiB
5Time limit exceeded1.564s29120 KiB
6Time limit exceeded1.569s35752 KiB
7Time limit exceeded1.56s39140 KiB
8Time limit exceeded1.569s39220 KiB
9Time limit exceeded1.58s39488 KiB
10Time limit exceeded1.567s39728 KiB
11Time limit exceeded1.562s40140 KiB
subtask30/35
12Accepted3ms3720 KiB
13Wrong answer3ms3808 KiB
14Wrong answer3ms3960 KiB
15Wrong answer3ms4148 KiB
16Wrong answer3ms4048 KiB
17Wrong answer4ms4420 KiB
18Wrong answer3ms4164 KiB
19Wrong answer4ms4536 KiB
20Wrong answer4ms4532 KiB
subtask40/45
21Accepted32ms4900 KiB
22Wrong answer59ms4292 KiB
23Time limit exceeded1.559s30512 KiB
24Wrong answer177ms4160 KiB
25Time limit exceeded1.577s40716 KiB
26Wrong answer187ms4372 KiB
27Time limit exceeded1.562s40668 KiB
28Wrong answer190ms4344 KiB
29Time limit exceeded1.552s40828 KiB