Submission #805709

# Submission time Handle Problem Language Result Execution time Memory
805709 2023-08-03T21:04:22 Z YesPy Monthly railway pass (LMIO18_menesinis_bilietas) C++17
16 / 100
346 ms 28824 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) 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 76 ms 2644 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 6 ms 6096 KB Output is correct
5 Correct 0 ms 468 KB Output is correct
6 Correct 31 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 6096 KB Output is correct
2 Correct 0 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 2 ms 724 KB Output is correct
6 Correct 199 ms 19132 KB Output is correct
7 Correct 346 ms 28824 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 340 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 2 ms 724 KB Output is correct
6 Correct 0 ms 340 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 1 ms 296 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Incorrect 2 ms 468 KB Output isn't correct
11 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 296 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Incorrect 2 ms 468 KB Output isn't correct
6 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 296 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Incorrect 2 ms 468 KB Output isn't correct
6 Halted 0 ms 0 KB -