// trenujsprostasarica.cpp : This file contains the 'main' function. Program execution begins and ends there.
//
// ejoiden2.cpp : This file contains the 'main' function. Program execution begins and ends there.
//
#include <iostream>
#include <vector>
#include <algorithm>
#include <set>
using namespace std;
vector<vector<int>>v;
//vector<int>dx = { -1,1,0,0 };
//vector<int>dy = { 0,0,-1,1 };
vector<int>otec;
vector<int>velkost;
int koren(int vr)
{
while (otec[vr] != vr)
{
vr = otec[vr];
}
return vr;
}
void merge(int a, int b)
{
a = koren(a);
b = koren(b);
if (a == b)
{
return;
}
if (velkost[a] < velkost[b])
{
swap(a, b);
}
otec[b] = a;
velkost[a] += velkost[b];
return;
}
bool suspojene(int a, int b)
{
a = koren(a);
b = koren(b);
if (a == b)
{
return true;
}
else
{
return false;
}
}
const int maxn = 500036;
set<int>s2[maxn];
int main()
{
int n;
cin >> n;
int m;
cin >> m;
v.resize(n);
velkost.resize(n, 1);
otec.resize(n);
for (int i = 0; i < n; i++)
{
otec[i] = i;
}
for (int i = 0; i < m; i++)
{
int a;
cin >> a;
int b;
cin >> b;
a -= 1;
b -= 1;
char typ;
cin >> typ;
if (typ == 'T')
{
merge(a, b);
}
else if (typ == 'A')
{
v[a].push_back(b);
v[b].push_back(a);
}
}
for (int i = 0; i < n; i++)
{
otec[i] = koren(i);
}
set<int>s;
for (int i = 0; i < n; i++)
{
s.insert(otec[i]);
}
for (int i = 0; i < n; i++)
{
s2[otec[i]].insert(otec[i]);
for (int j = 0; j < v[i].size(); j++)
{
s2[otec[i]].insert(otec[v[i][j]]);
}
}
int vys = 0;
for (int i = 0; i < n; i++)
{
if (s2[otec[i]].size() >= s.size())
{
vys += 1;
}
}
cout << vys << endl;
return 0;
//std::cout << "Hello World!\n";
}
// 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
Compilation message
menesinis_bilietas.cpp: In function 'int main()':
menesinis_bilietas.cpp:102:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
102 | for (int j = 0; j < v[i].size(); j++)
| ~~^~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
428 ms |
39996 KB |
Output is correct |
2 |
Correct |
15 ms |
23756 KB |
Output is correct |
3 |
Correct |
15 ms |
23756 KB |
Output is correct |
4 |
Correct |
196 ms |
82640 KB |
Output is correct |
5 |
Correct |
19 ms |
25292 KB |
Output is correct |
6 |
Correct |
159 ms |
26452 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
196 ms |
82640 KB |
Output is correct |
2 |
Correct |
19 ms |
25292 KB |
Output is correct |
3 |
Correct |
17 ms |
23792 KB |
Output is correct |
4 |
Correct |
17 ms |
23884 KB |
Output is correct |
5 |
Correct |
23 ms |
24652 KB |
Output is correct |
6 |
Correct |
429 ms |
68852 KB |
Output is correct |
7 |
Correct |
1008 ms |
133164 KB |
Output is correct |
8 |
Correct |
45 ms |
27776 KB |
Output is correct |
9 |
Correct |
54 ms |
29248 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
15 ms |
23756 KB |
Output is correct |
2 |
Correct |
15 ms |
23756 KB |
Output is correct |
3 |
Correct |
17 ms |
23792 KB |
Output is correct |
4 |
Correct |
17 ms |
23884 KB |
Output is correct |
5 |
Correct |
23 ms |
24652 KB |
Output is correct |
6 |
Correct |
16 ms |
23728 KB |
Output is correct |
7 |
Correct |
16 ms |
23764 KB |
Output is correct |
8 |
Correct |
18 ms |
23804 KB |
Output is correct |
9 |
Correct |
19 ms |
23884 KB |
Output is correct |
10 |
Correct |
26 ms |
24048 KB |
Output is correct |
11 |
Correct |
20 ms |
24080 KB |
Output is correct |
12 |
Correct |
16 ms |
23756 KB |
Output is correct |
13 |
Correct |
16 ms |
23756 KB |
Output is correct |
14 |
Correct |
25 ms |
24260 KB |
Output is correct |
15 |
Correct |
16 ms |
23784 KB |
Output is correct |
16 |
Correct |
17 ms |
23760 KB |
Output is correct |
17 |
Correct |
15 ms |
23756 KB |
Output is correct |
18 |
Correct |
17 ms |
23824 KB |
Output is correct |
19 |
Correct |
17 ms |
23768 KB |
Output is correct |
20 |
Correct |
18 ms |
23916 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
16 ms |
23728 KB |
Output is correct |
2 |
Correct |
16 ms |
23764 KB |
Output is correct |
3 |
Correct |
18 ms |
23804 KB |
Output is correct |
4 |
Correct |
19 ms |
23884 KB |
Output is correct |
5 |
Correct |
26 ms |
24048 KB |
Output is correct |
6 |
Correct |
20 ms |
24080 KB |
Output is correct |
7 |
Correct |
16 ms |
23756 KB |
Output is correct |
8 |
Correct |
16 ms |
23756 KB |
Output is correct |
9 |
Correct |
25 ms |
24260 KB |
Output is correct |
10 |
Correct |
16 ms |
23784 KB |
Output is correct |
11 |
Correct |
17 ms |
23760 KB |
Output is correct |
12 |
Correct |
15 ms |
23756 KB |
Output is correct |
13 |
Correct |
17 ms |
23824 KB |
Output is correct |
14 |
Correct |
17 ms |
23768 KB |
Output is correct |
15 |
Correct |
18 ms |
23916 KB |
Output is correct |
16 |
Correct |
15 ms |
23756 KB |
Output is correct |
17 |
Correct |
15 ms |
23756 KB |
Output is correct |
18 |
Correct |
17 ms |
23792 KB |
Output is correct |
19 |
Correct |
17 ms |
23884 KB |
Output is correct |
20 |
Correct |
23 ms |
24652 KB |
Output is correct |
21 |
Correct |
19 ms |
25292 KB |
Output is correct |
22 |
Correct |
45 ms |
27776 KB |
Output is correct |
23 |
Correct |
54 ms |
29248 KB |
Output is correct |
24 |
Correct |
159 ms |
26452 KB |
Output is correct |
25 |
Correct |
38 ms |
24512 KB |
Output is correct |
26 |
Correct |
335 ms |
33464 KB |
Output is correct |
27 |
Correct |
125 ms |
27208 KB |
Output is correct |
28 |
Correct |
199 ms |
39364 KB |
Output is correct |
29 |
Correct |
106 ms |
26880 KB |
Output is correct |
30 |
Correct |
215 ms |
37696 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
16 ms |
23728 KB |
Output is correct |
2 |
Correct |
16 ms |
23764 KB |
Output is correct |
3 |
Correct |
18 ms |
23804 KB |
Output is correct |
4 |
Correct |
19 ms |
23884 KB |
Output is correct |
5 |
Correct |
26 ms |
24048 KB |
Output is correct |
6 |
Correct |
20 ms |
24080 KB |
Output is correct |
7 |
Correct |
16 ms |
23756 KB |
Output is correct |
8 |
Correct |
16 ms |
23756 KB |
Output is correct |
9 |
Correct |
25 ms |
24260 KB |
Output is correct |
10 |
Correct |
16 ms |
23784 KB |
Output is correct |
11 |
Correct |
17 ms |
23760 KB |
Output is correct |
12 |
Correct |
15 ms |
23756 KB |
Output is correct |
13 |
Correct |
17 ms |
23824 KB |
Output is correct |
14 |
Correct |
17 ms |
23768 KB |
Output is correct |
15 |
Correct |
18 ms |
23916 KB |
Output is correct |
16 |
Correct |
38 ms |
24512 KB |
Output is correct |
17 |
Correct |
335 ms |
33464 KB |
Output is correct |
18 |
Correct |
125 ms |
27208 KB |
Output is correct |
19 |
Correct |
199 ms |
39364 KB |
Output is correct |
20 |
Correct |
106 ms |
26880 KB |
Output is correct |
21 |
Correct |
215 ms |
37696 KB |
Output is correct |
22 |
Correct |
428 ms |
39996 KB |
Output is correct |
23 |
Correct |
15 ms |
23756 KB |
Output is correct |
24 |
Correct |
15 ms |
23756 KB |
Output is correct |
25 |
Correct |
196 ms |
82640 KB |
Output is correct |
26 |
Correct |
17 ms |
23792 KB |
Output is correct |
27 |
Correct |
17 ms |
23884 KB |
Output is correct |
28 |
Correct |
23 ms |
24652 KB |
Output is correct |
29 |
Correct |
19 ms |
25292 KB |
Output is correct |
30 |
Correct |
429 ms |
68852 KB |
Output is correct |
31 |
Correct |
1008 ms |
133164 KB |
Output is correct |
32 |
Correct |
45 ms |
27776 KB |
Output is correct |
33 |
Correct |
54 ms |
29248 KB |
Output is correct |
34 |
Correct |
159 ms |
26452 KB |
Output is correct |
35 |
Correct |
83 ms |
27872 KB |
Output is correct |
36 |
Correct |
629 ms |
42916 KB |
Output is correct |
37 |
Correct |
206 ms |
33348 KB |
Output is correct |