Submission #805702

# Submission time Handle Problem Language Result Execution time Memory
805702 2023-08-03T20:56:37 Z YesPy Monthly railway pass (LMIO18_menesinis_bilietas) C++17
16 / 100
334 ms 28816 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;
	else 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) orz.insert({find(z.ff), find(z.ss)});

	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 2648 KB Output is correct
2 Correct 0 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 412 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 0 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 3 ms 708 KB Output is correct
6 Correct 192 ms 19068 KB Output is correct
7 Correct 334 ms 28816 KB Output is correct
8 Correct 5 ms 1364 KB Output is correct
9 Correct 11 ms 2136 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 0 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 3 ms 708 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 340 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 452 KB Output is correct
11 Correct 2 ms 468 KB Output is correct
12 Correct 0 ms 340 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 4 ms 468 KB Output is correct
15 Correct 0 ms 340 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
17 Incorrect 0 ms 340 KB Output isn't correct
18 Halted 0 ms 0 KB -
# 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 2 ms 452 KB Output is correct
6 Correct 2 ms 468 KB Output is correct
7 Correct 0 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 4 ms 468 KB Output is correct
10 Correct 0 ms 340 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Incorrect 0 ms 340 KB Output isn't correct
13 Halted 0 ms 0 KB -
# 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 2 ms 452 KB Output is correct
6 Correct 2 ms 468 KB Output is correct
7 Correct 0 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 4 ms 468 KB Output is correct
10 Correct 0 ms 340 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Incorrect 0 ms 340 KB Output isn't correct
13 Halted 0 ms 0 KB -