Submission #826376

# Submission time Handle Problem Language Result Execution time Memory
826376 2023-08-15T13:42:10 Z OAleksa Monthly railway pass (LMIO18_menesinis_bilietas) C++14
16 / 100
351 ms 59428 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];
		}
		if(c == 1)
			ans = n;
		cout << ans;
	}
   return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 244 ms 49552 KB Output is correct
2 Correct 13 ms 27684 KB Output is correct
3 Correct 12 ms 27708 KB Output is correct
4 Correct 14 ms 27604 KB Output is correct
5 Correct 11 ms 27732 KB Output is correct
6 Correct 42 ms 32760 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 14 ms 27604 KB Output is correct
2 Correct 11 ms 27732 KB Output is correct
3 Correct 11 ms 27732 KB Output is correct
4 Correct 12 ms 27732 KB Output is correct
5 Correct 15 ms 28292 KB Output is correct
6 Correct 230 ms 53468 KB Output is correct
7 Correct 351 ms 59428 KB Output is correct
8 Correct 16 ms 28888 KB Output is correct
9 Correct 23 ms 29908 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 13 ms 27684 KB Output is correct
2 Correct 12 ms 27708 KB Output is correct
3 Correct 11 ms 27732 KB Output is correct
4 Correct 12 ms 27732 KB Output is correct
5 Correct 15 ms 28292 KB Output is correct
6 Correct 11 ms 27604 KB Output is correct
7 Correct 10 ms 27604 KB Output is correct
8 Correct 12 ms 27732 KB Output is correct
9 Correct 12 ms 27892 KB Output is correct
10 Correct 13 ms 28116 KB Output is correct
11 Correct 13 ms 27948 KB Output is correct
12 Correct 12 ms 27732 KB Output is correct
13 Correct 11 ms 27732 KB Output is correct
14 Correct 14 ms 28160 KB Output is correct
15 Correct 11 ms 27732 KB Output is correct
16 Correct 12 ms 27732 KB Output is correct
17 Incorrect 11 ms 27732 KB Output isn't correct
18 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 11 ms 27604 KB Output is correct
2 Correct 10 ms 27604 KB Output is correct
3 Correct 12 ms 27732 KB Output is correct
4 Correct 12 ms 27892 KB Output is correct
5 Correct 13 ms 28116 KB Output is correct
6 Correct 13 ms 27948 KB Output is correct
7 Correct 12 ms 27732 KB Output is correct
8 Correct 11 ms 27732 KB Output is correct
9 Correct 14 ms 28160 KB Output is correct
10 Correct 11 ms 27732 KB Output is correct
11 Correct 12 ms 27732 KB Output is correct
12 Incorrect 11 ms 27732 KB Output isn't correct
13 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 11 ms 27604 KB Output is correct
2 Correct 10 ms 27604 KB Output is correct
3 Correct 12 ms 27732 KB Output is correct
4 Correct 12 ms 27892 KB Output is correct
5 Correct 13 ms 28116 KB Output is correct
6 Correct 13 ms 27948 KB Output is correct
7 Correct 12 ms 27732 KB Output is correct
8 Correct 11 ms 27732 KB Output is correct
9 Correct 14 ms 28160 KB Output is correct
10 Correct 11 ms 27732 KB Output is correct
11 Correct 12 ms 27732 KB Output is correct
12 Incorrect 11 ms 27732 KB Output isn't correct
13 Halted 0 ms 0 KB -