답안 #826361

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
826361 2023-08-15T13:29:12 Z OAleksa Monthly railway pass (LMIO18_menesinis_bilietas) C++14
6 / 100
355 ms 59432 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];
			else if(sz[i] == n)
				ans = n;
		}
		cout << ans;
	}
   return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Incorrect 247 ms 49636 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 18 ms 27732 KB Output is correct
2 Correct 11 ms 27648 KB Output is correct
3 Correct 11 ms 27732 KB Output is correct
4 Correct 14 ms 28308 KB Output is correct
5 Correct 11 ms 27632 KB Output is correct
6 Correct 244 ms 53416 KB Output is correct
7 Correct 355 ms 59432 KB Output is correct
8 Correct 19 ms 28916 KB Output is correct
9 Correct 24 ms 29836 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 11 ms 27648 KB Output is correct
2 Correct 11 ms 27732 KB Output is correct
3 Correct 14 ms 28308 KB Output is correct
4 Correct 14 ms 27608 KB Output is correct
5 Correct 12 ms 27732 KB Output is correct
6 Correct 12 ms 27732 KB Output is correct
7 Correct 12 ms 27860 KB Output is correct
8 Incorrect 13 ms 28020 KB Output isn't correct
9 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 14 ms 27608 KB Output is correct
2 Correct 12 ms 27732 KB Output is correct
3 Correct 12 ms 27732 KB Output is correct
4 Correct 12 ms 27860 KB Output is correct
5 Incorrect 13 ms 28020 KB Output isn't correct
6 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 14 ms 27608 KB Output is correct
2 Correct 12 ms 27732 KB Output is correct
3 Correct 12 ms 27732 KB Output is correct
4 Correct 12 ms 27860 KB Output is correct
5 Incorrect 13 ms 28020 KB Output isn't correct
6 Halted 0 ms 0 KB -