Submission #805715

# Submission time Handle Problem Language Result Execution time Memory
805715 2023-08-03T21:14:12 Z YesPy Monthly railway pass (LMIO18_menesinis_bilietas) C++17
100 / 100
311 ms 28800 KB
#include <bits/stdc++.h>

#define ff first
#define ss second
#define tcT template<class T
#define fastio ios::sync_with_stdio(false);cin.tie(nullptr);
#define ln '\n'
#define nwln cout<<ln;

using namespace std;

tcT> using vr = vector<T>;
using pi = pair<int, int>;
using vi = vr<int>;
using vpi = vr<pi>;

#define fri(i,a,b) for(int i=(a); i<(b); ++i)
#define each(x, a) for(auto& x: a)

#define sz(x) int((x).size())
#define phb push_back
#define eb emplace_back

const int MX = (int) 5e5+3;
int N, M, par[MX], len[MX], deg[MX], ans;
vpi bus;
vi fathers;

inline int find(int u) {
	if(par[u] == u) return u;
	return par[u] = find(par[u]);
}

void uni(int u, int v) {
	u = find(u), v = find(v);
	if(u == v) return;

	if(len[u] < len[v]) swap(u, v);
	par[v] = u, len[u] += len[v];
}

int main()
{
	fastio
	cin>>N>>M;

	fri(i,1,N+1) par[i] = i, len[i] = 1;

	while(M--) {
		int u, v;
		char ty;
		cin>>u>>v>>ty;

		if(ty == 'A') bus.eb(u, v);
		else uni(find(u), find(v));
	}

	fri(i,1,N+1) {
		if(par[i] == i) fathers.eb(i);
	}

	set<pi> orz;
	each(z, bus) {
		z.ff = find(z.ff), z.ss = find(z.ss);
		if(z.ff == z.ss) continue;
		orz.insert(z);
	}

	each(z, orz) ++deg[z.ff], ++deg[z.ss];
	
	each(x, fathers) {
		if(deg[x] == sz(fathers)-1) ans += len[x];
	}

	cout<<ans<<ln;

	return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 77 ms 2656 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 5 ms 6096 KB Output is correct
5 Correct 1 ms 468 KB Output is correct
6 Correct 24 ms 408 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 6096 KB Output is correct
2 Correct 1 ms 468 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 3 ms 724 KB Output is correct
6 Correct 251 ms 19004 KB Output is correct
7 Correct 311 ms 28800 KB Output is correct
8 Correct 6 ms 1364 KB Output is correct
9 Correct 11 ms 2136 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 3 ms 724 KB Output is correct
6 Correct 0 ms 340 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 2 ms 468 KB Output is correct
11 Correct 2 ms 468 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 0 ms 340 KB Output is correct
14 Correct 3 ms 468 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
17 Correct 0 ms 212 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
20 Correct 1 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 2 ms 468 KB Output is correct
6 Correct 2 ms 468 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 0 ms 340 KB Output is correct
9 Correct 3 ms 468 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 1 ms 212 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
20 Correct 3 ms 724 KB Output is correct
21 Correct 1 ms 468 KB Output is correct
22 Correct 6 ms 1364 KB Output is correct
23 Correct 11 ms 2136 KB Output is correct
24 Correct 24 ms 408 KB Output is correct
25 Correct 6 ms 736 KB Output is correct
26 Correct 84 ms 4544 KB Output is correct
27 Correct 35 ms 4044 KB Output is correct
28 Correct 77 ms 9524 KB Output is correct
29 Correct 32 ms 2756 KB Output is correct
30 Correct 57 ms 8516 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 2 ms 468 KB Output is correct
6 Correct 2 ms 468 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 0 ms 340 KB Output is correct
9 Correct 3 ms 468 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 6 ms 736 KB Output is correct
17 Correct 84 ms 4544 KB Output is correct
18 Correct 35 ms 4044 KB Output is correct
19 Correct 77 ms 9524 KB Output is correct
20 Correct 32 ms 2756 KB Output is correct
21 Correct 57 ms 8516 KB Output is correct
22 Correct 77 ms 2656 KB Output is correct
23 Correct 1 ms 212 KB Output is correct
24 Correct 1 ms 340 KB Output is correct
25 Correct 5 ms 6096 KB Output is correct
26 Correct 1 ms 340 KB Output is correct
27 Correct 1 ms 340 KB Output is correct
28 Correct 3 ms 724 KB Output is correct
29 Correct 1 ms 468 KB Output is correct
30 Correct 251 ms 19004 KB Output is correct
31 Correct 311 ms 28800 KB Output is correct
32 Correct 6 ms 1364 KB Output is correct
33 Correct 11 ms 2136 KB Output is correct
34 Correct 24 ms 408 KB Output is correct
35 Correct 17 ms 2512 KB Output is correct
36 Correct 131 ms 12312 KB Output is correct
37 Correct 38 ms 5668 KB Output is correct