Submission #237063

# Submission time Handle Problem Language Result Execution time Memory
237063 2020-06-04T11:10:48 Z Berted Monthly railway pass (LMIO18_menesinis_bilietas) C++14
100 / 100
733 ms 70060 KB
#include <iostream>
#include <vector>
#include <set>
#define pii pair<int, int>
#define pub push_back
#define si set<int>
#define fst first
#define snd second
using namespace std;
int n, m, pr[500001] = {}, sz[500001] = {}, comp = 0;
vector<pii> edge;
vector<si> adj;
int findRep(int x) {return pr[x] = (pr[x] == x) ? x : findRep(pr[x]);}
void joinG(int a, int b)
{
	a = findRep(a), b = findRep(b);
	if (a != b)
	{
		pr[b] = a;
		sz[a] += sz[b];
		sz[b] = 0;
		comp--;
	}
}
int main()
{
	ios :: sync_with_stdio(0); cin.tie(0); cout.tie(0);
	int res = 0;
	cin >> n >> m;
	for (int i = 0; i < n; i++) {adj.pub(si()); pr[i] = i; sz[i] = 1;}
	comp = n;
	for (int i = 0; i < m; i++)
	{
		int u, v; char c; cin >> u >> v >> c;
		if (c == 'T') {joinG(u - 1, v - 1);}
		else {edge.pub({u - 1, v - 1});}
	}
	for (int i = 0; i < edge.size(); i++)
	{
		int u = findRep(edge[i].fst), v = findRep(edge[i].snd);
		if (u != v) 
		{
			adj[u].insert(v);
			adj[v].insert(u);
		}
	}
	for (int i = 0; i < n; i++)
	{
		if (adj[i].size() == comp - 1) {res += sz[i];}
	}
	cout << res << "\n";
	return 0;
}

Compilation message

menesinis_bilietas.cpp: In function 'int main()':
menesinis_bilietas.cpp:38:20: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for (int i = 0; i < edge.size(); i++)
                  ~~^~~~~~~~~~~~~
menesinis_bilietas.cpp:49:21: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   if (adj[i].size() == comp - 1) {res += sz[i];}
       ~~~~~~~~~~~~~~^~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 190 ms 27240 KB Output is correct
2 Correct 5 ms 256 KB Output is correct
3 Correct 5 ms 384 KB Output is correct
4 Correct 33 ms 27240 KB Output is correct
5 Correct 5 ms 1276 KB Output is correct
6 Correct 46 ms 3316 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 33 ms 27240 KB Output is correct
2 Correct 5 ms 384 KB Output is correct
3 Correct 5 ms 512 KB Output is correct
4 Correct 9 ms 1280 KB Output is correct
5 Correct 5 ms 1276 KB Output is correct
6 Correct 572 ms 40824 KB Output is correct
7 Correct 733 ms 70060 KB Output is correct
8 Correct 14 ms 2936 KB Output is correct
9 Correct 24 ms 4344 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 5 ms 384 KB Output is correct
3 Correct 6 ms 384 KB Output is correct
4 Correct 6 ms 512 KB Output is correct
5 Correct 7 ms 640 KB Output is correct
6 Correct 7 ms 640 KB Output is correct
7 Correct 5 ms 384 KB Output is correct
8 Correct 5 ms 384 KB Output is correct
9 Correct 9 ms 768 KB Output is correct
10 Correct 5 ms 384 KB Output is correct
11 Correct 5 ms 512 KB Output is correct
12 Correct 5 ms 384 KB Output is correct
13 Correct 6 ms 512 KB Output is correct
14 Correct 5 ms 384 KB Output is correct
15 Correct 6 ms 512 KB Output is correct
16 Correct 5 ms 256 KB Output is correct
17 Correct 5 ms 384 KB Output is correct
18 Correct 5 ms 384 KB Output is correct
19 Correct 5 ms 512 KB Output is correct
20 Correct 9 ms 1280 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 5 ms 384 KB Output is correct
3 Correct 6 ms 384 KB Output is correct
4 Correct 6 ms 512 KB Output is correct
5 Correct 7 ms 640 KB Output is correct
6 Correct 7 ms 640 KB Output is correct
7 Correct 5 ms 384 KB Output is correct
8 Correct 5 ms 384 KB Output is correct
9 Correct 9 ms 768 KB Output is correct
10 Correct 5 ms 384 KB Output is correct
11 Correct 5 ms 512 KB Output is correct
12 Correct 5 ms 384 KB Output is correct
13 Correct 6 ms 512 KB Output is correct
14 Correct 5 ms 384 KB Output is correct
15 Correct 6 ms 512 KB Output is correct
16 Correct 15 ms 1152 KB Output is correct
17 Correct 145 ms 9184 KB Output is correct
18 Correct 55 ms 3956 KB Output is correct
19 Correct 224 ms 15340 KB Output is correct
20 Correct 52 ms 3052 KB Output is correct
21 Correct 180 ms 13928 KB Output is correct
22 Correct 5 ms 256 KB Output is correct
23 Correct 5 ms 384 KB Output is correct
24 Correct 5 ms 384 KB Output is correct
25 Correct 5 ms 512 KB Output is correct
26 Correct 9 ms 1280 KB Output is correct
27 Correct 5 ms 1276 KB Output is correct
28 Correct 14 ms 2936 KB Output is correct
29 Correct 24 ms 4344 KB Output is correct
30 Correct 46 ms 3316 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 5 ms 384 KB Output is correct
3 Correct 6 ms 384 KB Output is correct
4 Correct 6 ms 512 KB Output is correct
5 Correct 7 ms 640 KB Output is correct
6 Correct 7 ms 640 KB Output is correct
7 Correct 5 ms 384 KB Output is correct
8 Correct 5 ms 384 KB Output is correct
9 Correct 9 ms 768 KB Output is correct
10 Correct 5 ms 384 KB Output is correct
11 Correct 5 ms 512 KB Output is correct
12 Correct 5 ms 384 KB Output is correct
13 Correct 6 ms 512 KB Output is correct
14 Correct 5 ms 384 KB Output is correct
15 Correct 6 ms 512 KB Output is correct
16 Correct 15 ms 1152 KB Output is correct
17 Correct 145 ms 9184 KB Output is correct
18 Correct 55 ms 3956 KB Output is correct
19 Correct 224 ms 15340 KB Output is correct
20 Correct 52 ms 3052 KB Output is correct
21 Correct 180 ms 13928 KB Output is correct
22 Correct 190 ms 27240 KB Output is correct
23 Correct 5 ms 256 KB Output is correct
24 Correct 5 ms 384 KB Output is correct
25 Correct 33 ms 27240 KB Output is correct
26 Correct 5 ms 384 KB Output is correct
27 Correct 5 ms 512 KB Output is correct
28 Correct 9 ms 1280 KB Output is correct
29 Correct 5 ms 1276 KB Output is correct
30 Correct 572 ms 40824 KB Output is correct
31 Correct 733 ms 70060 KB Output is correct
32 Correct 36 ms 4588 KB Output is correct
33 Correct 286 ms 18648 KB Output is correct
34 Correct 77 ms 14536 KB Output is correct
35 Correct 14 ms 2936 KB Output is correct
36 Correct 24 ms 4344 KB Output is correct
37 Correct 46 ms 3316 KB Output is correct