Submission #826360

# Submission time Handle Problem Language Result Execution time Memory
826360 2023-08-15T13:28:10 Z OAleksa Monthly railway pass (LMIO18_menesinis_bilietas) C++14
6 / 100
394 ms 65584 KB
#include <bits/stdc++.h>
#define f first
#define s second
using namespace std; 
#define int long long
const int maxn = 5e5 + 69;
vector<int> g[maxn];
vector<int> p(maxn), sz(maxn);
vector<int> deg(maxn), vis(maxn);
int find_set(int v) {
	if(p[v] == v)
		return v;
	return p[v] = find_set(p[v]);
}

void unite(int a, int b) {
	a = find_set(a);
	b = find_set(b);
	if(a != b) {
		if(sz[a] < sz[b])	
			swap(a, b);
		p[b] = a;
		sz[a] += sz[b];
	}
}

void dfs(int v) {
	vis[v] = 1;
	for(auto u : g[v]) {
		if(!vis[u]) {
			unite(u, v);
			dfs(u);
		}
	}
}

signed main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	int tt = 1;
	//cin >> tt;
	while(tt--) {
		int n, m;
		cin >> n >> m;
		vector<pair<int, int>> edges;
		for(int i = 1;i <= n;i++) {
			p[i] = i;
			sz[i] = 1;
		}
		for(int i = 0;i < m;i++) {
			int a, b;
			char c;
			cin >> a >> b >> c;
			if(c == 'T') {
				g[a].push_back(b);
				g[b].push_back(a);
			}
			else 
				edges.push_back({a, b});
		}
		int c = 0;
		for(int i = 1;i <= n;i++) {
			if(!vis[i]) {
				dfs(i);
				++c;
			}
		}
		int ans = 0;
		set<pair<int, int>> bio;
		for(auto x : edges) {
			int a = find_set(x.f);
			int b = find_set(x.s);
			if(a > b)
				swap(a, b);
			if(bio.count({a, b}))
				continue;
			else {
				bio.insert({a, b});
				deg[a]++;
				deg[b]++;
			}
		}
		for(int i = 1;i <= n;i++) {
			if(deg[i] == c - 1)
				ans += sz[i];
		}
		cout << ans;
	}
   return 0;
}
# Verdict Execution time Memory Grader output
1 Incorrect 281 ms 56316 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 15 ms 27688 KB Output is correct
2 Correct 12 ms 27728 KB Output is correct
3 Correct 12 ms 27732 KB Output is correct
4 Correct 16 ms 28372 KB Output is correct
5 Correct 11 ms 27732 KB Output is correct
6 Correct 232 ms 57836 KB Output is correct
7 Correct 394 ms 65584 KB Output is correct
8 Correct 20 ms 29016 KB Output is correct
9 Correct 25 ms 30176 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 12 ms 27728 KB Output is correct
2 Correct 12 ms 27732 KB Output is correct
3 Correct 16 ms 28372 KB Output is correct
4 Correct 11 ms 27732 KB Output is correct
5 Correct 12 ms 27668 KB Output is correct
6 Correct 13 ms 27840 KB Output is correct
7 Correct 13 ms 27876 KB Output is correct
8 Incorrect 14 ms 28116 KB Output isn't correct
9 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 11 ms 27732 KB Output is correct
2 Correct 12 ms 27668 KB Output is correct
3 Correct 13 ms 27840 KB Output is correct
4 Correct 13 ms 27876 KB Output is correct
5 Incorrect 14 ms 28116 KB Output isn't correct
6 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 11 ms 27732 KB Output is correct
2 Correct 12 ms 27668 KB Output is correct
3 Correct 13 ms 27840 KB Output is correct
4 Correct 13 ms 27876 KB Output is correct
5 Incorrect 14 ms 28116 KB Output isn't correct
6 Halted 0 ms 0 KB -