답안 #920858

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
920858 2024-02-03T06:35:30 Z yhkhoo Monthly railway pass (LMIO18_menesinis_bilietas) C++17
100 / 100
536 ms 110560 KB
#include <bits/stdc++.h>
using namespace std;

typedef pair<int, int> pii;

vector<int> p;

int get_parent(int x){
	if(p[x] == x) return x;
	p[x] = get_parent(p[x]);
	return p[x];
}

void union_set(int u, int v){
	u = get_parent(u);
	v = get_parent(v);
	if(u==v) return;
	p[u] = v;
}

int main(){
	cin.tie(0); ios_base::sync_with_stdio(0);
	int n, m;
	cin >> n >> m;
	p.clear();
	p.reserve(n);
	for(int i=0; i<n; i++){
		p.push_back(i);
	}
	vector<pii> bus;
	bus.reserve(m);
	for(int i=0; i<m; i++){
		int a, b;
		char t;
		cin >> a >> b >> t;
		a--; b--;
		if(t=='T'){
			union_set(a, b);
		}
		else{
			bus.emplace_back(a, b);
		}
	}
	vector<int> ss(n, 0);
	for(int i=0; i<n; i++){
		ss[get_parent(i)]++;
	}
	int nc=0;
	for(int i=0; i<n; i++){
		if(ss[i] != 0){
			nc++;
		}
	}
	vector<unordered_set<int>> sadj(n);
	for(auto i: bus){
		int a = get_parent(i.first);
		int b = get_parent(i.second);
		if(a==b) continue;
		sadj[a].insert(b);
		sadj[b].insert(a);
	}
	int ans=0;
	for(int i=0; i<n; i++){
		if(sadj[i].size() == nc-1){
			ans += ss[i];
		}
	}
	cout << ans;
	return 0;
}

Compilation message

menesinis_bilietas.cpp: In function 'int main()':
menesinis_bilietas.cpp:64:21: warning: comparison of integer expressions of different signedness: 'std::unordered_set<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   64 |   if(sadj[i].size() == nc-1){
      |      ~~~~~~~~~~~~~~~^~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 103 ms 19024 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 15 ms 29788 KB Output is correct
5 Correct 1 ms 1220 KB Output is correct
6 Correct 26 ms 3160 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 15 ms 29788 KB Output is correct
2 Correct 1 ms 1220 KB Output is correct
3 Correct 1 ms 344 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 3 ms 1116 KB Output is correct
6 Correct 332 ms 40744 KB Output is correct
7 Correct 536 ms 110560 KB Output is correct
8 Correct 9 ms 4408 KB Output is correct
9 Correct 13 ms 5464 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 1 ms 344 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 3 ms 1116 KB Output is correct
6 Correct 0 ms 344 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 1 ms 344 KB Output is correct
9 Correct 1 ms 544 KB Output is correct
10 Correct 2 ms 568 KB Output is correct
11 Correct 1 ms 604 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 2 ms 860 KB Output is correct
15 Correct 0 ms 452 KB Output is correct
16 Correct 1 ms 348 KB Output is correct
17 Correct 1 ms 544 KB Output is correct
18 Correct 1 ms 604 KB Output is correct
19 Correct 1 ms 348 KB Output is correct
20 Correct 1 ms 604 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 1 ms 344 KB Output is correct
4 Correct 1 ms 544 KB Output is correct
5 Correct 2 ms 568 KB Output is correct
6 Correct 1 ms 604 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 2 ms 860 KB Output is correct
10 Correct 0 ms 452 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 1 ms 544 KB Output is correct
13 Correct 1 ms 604 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 1 ms 604 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 1 ms 344 KB Output is correct
19 Correct 1 ms 348 KB Output is correct
20 Correct 3 ms 1116 KB Output is correct
21 Correct 1 ms 1220 KB Output is correct
22 Correct 9 ms 4408 KB Output is correct
23 Correct 13 ms 5464 KB Output is correct
24 Correct 26 ms 3160 KB Output is correct
25 Correct 5 ms 1116 KB Output is correct
26 Correct 63 ms 8660 KB Output is correct
27 Correct 24 ms 3216 KB Output is correct
28 Correct 79 ms 13648 KB Output is correct
29 Correct 18 ms 2908 KB Output is correct
30 Correct 60 ms 12884 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 1 ms 344 KB Output is correct
4 Correct 1 ms 544 KB Output is correct
5 Correct 2 ms 568 KB Output is correct
6 Correct 1 ms 604 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 2 ms 860 KB Output is correct
10 Correct 0 ms 452 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 1 ms 544 KB Output is correct
13 Correct 1 ms 604 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 1 ms 604 KB Output is correct
16 Correct 5 ms 1116 KB Output is correct
17 Correct 63 ms 8660 KB Output is correct
18 Correct 24 ms 3216 KB Output is correct
19 Correct 79 ms 13648 KB Output is correct
20 Correct 18 ms 2908 KB Output is correct
21 Correct 60 ms 12884 KB Output is correct
22 Correct 103 ms 19024 KB Output is correct
23 Correct 0 ms 348 KB Output is correct
24 Correct 0 ms 348 KB Output is correct
25 Correct 15 ms 29788 KB Output is correct
26 Correct 1 ms 344 KB Output is correct
27 Correct 1 ms 348 KB Output is correct
28 Correct 3 ms 1116 KB Output is correct
29 Correct 1 ms 1220 KB Output is correct
30 Correct 332 ms 40744 KB Output is correct
31 Correct 536 ms 110560 KB Output is correct
32 Correct 9 ms 4408 KB Output is correct
33 Correct 13 ms 5464 KB Output is correct
34 Correct 26 ms 3160 KB Output is correct
35 Correct 16 ms 4696 KB Output is correct
36 Correct 92 ms 18868 KB Output is correct
37 Correct 41 ms 16208 KB Output is correct