Submission #920975

# Submission time Handle Problem Language Result Execution time Memory
920975 2024-02-03T08:35:06 Z WongYiKai Monthly railway pass (LMIO18_menesinis_bilietas) C++14
100 / 100
401 ms 114360 KB
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

ll visited[600000];
ll type[600000];
ll c=1;
ll sets[600000];

vector<ll> adj[600000],adj2[600000];

void dfs(ll vertex){
	visited[vertex] = 1;
	type[vertex] = c;
	sets[c]++;
	for (auto item:adj[vertex]){
		if (visited[item]==0){
			dfs(item);
		}
	}
}
int main(){
	ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	ll n,m;
	cin >> n >> m;
	for (int i=0;i<m;i++){
		ll a,b;
		char t;
		cin >> a >> b >> t;
		if (t=='T'){
			adj[a].push_back(b);
			adj[b].push_back(a);
		}
		else {
			adj2[a].push_back(b);
			adj2[b].push_back(a);
		}
	}
	for (int i=1;i<=n;i++){
		if (visited[i]==0){
			dfs(i);
			c++;
		}
	}
	set<ll> con[c+5];
	for (int i=1;i<=n;i++){
		for (auto item:adj2[i]){
			if (type[i]!=type[item]){
				con[type[i]].insert(type[item]);
			}
		}
	}
	c--;
	ll total=0;
	for (int i=1;i<=c;i++){
		//cout << con[i].size() << "\n";
		ll len = con[i].size();
		if (len == c-1) total += sets[i];
	}
	cout << total;
}
# Verdict Execution time Memory Grader output
1 Correct 306 ms 57428 KB Output is correct
2 Correct 8 ms 31320 KB Output is correct
3 Correct 9 ms 31320 KB Output is correct
4 Correct 29 ms 63324 KB Output is correct
5 Correct 9 ms 32088 KB Output is correct
6 Correct 40 ms 36436 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 29 ms 63324 KB Output is correct
2 Correct 9 ms 32088 KB Output is correct
3 Correct 8 ms 31320 KB Output is correct
4 Correct 10 ms 31544 KB Output is correct
5 Correct 11 ms 32088 KB Output is correct
6 Correct 178 ms 73328 KB Output is correct
7 Correct 401 ms 114360 KB Output is correct
8 Correct 17 ms 34140 KB Output is correct
9 Correct 20 ms 35676 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 8 ms 31320 KB Output is correct
2 Correct 9 ms 31320 KB Output is correct
3 Correct 8 ms 31320 KB Output is correct
4 Correct 10 ms 31544 KB Output is correct
5 Correct 11 ms 32088 KB Output is correct
6 Correct 8 ms 31324 KB Output is correct
7 Correct 8 ms 31420 KB Output is correct
8 Correct 9 ms 31324 KB Output is correct
9 Correct 9 ms 31632 KB Output is correct
10 Correct 11 ms 31580 KB Output is correct
11 Correct 10 ms 31836 KB Output is correct
12 Correct 8 ms 31324 KB Output is correct
13 Correct 9 ms 31324 KB Output is correct
14 Correct 11 ms 31836 KB Output is correct
15 Correct 10 ms 31324 KB Output is correct
16 Correct 9 ms 31376 KB Output is correct
17 Correct 9 ms 31324 KB Output is correct
18 Correct 9 ms 31572 KB Output is correct
19 Correct 10 ms 31324 KB Output is correct
20 Correct 10 ms 31428 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 8 ms 31324 KB Output is correct
2 Correct 8 ms 31420 KB Output is correct
3 Correct 9 ms 31324 KB Output is correct
4 Correct 9 ms 31632 KB Output is correct
5 Correct 11 ms 31580 KB Output is correct
6 Correct 10 ms 31836 KB Output is correct
7 Correct 8 ms 31324 KB Output is correct
8 Correct 9 ms 31324 KB Output is correct
9 Correct 11 ms 31836 KB Output is correct
10 Correct 10 ms 31324 KB Output is correct
11 Correct 9 ms 31376 KB Output is correct
12 Correct 9 ms 31324 KB Output is correct
13 Correct 9 ms 31572 KB Output is correct
14 Correct 10 ms 31324 KB Output is correct
15 Correct 10 ms 31428 KB Output is correct
16 Correct 8 ms 31320 KB Output is correct
17 Correct 9 ms 31320 KB Output is correct
18 Correct 8 ms 31320 KB Output is correct
19 Correct 10 ms 31544 KB Output is correct
20 Correct 11 ms 32088 KB Output is correct
21 Correct 9 ms 32088 KB Output is correct
22 Correct 17 ms 34140 KB Output is correct
23 Correct 20 ms 35676 KB Output is correct
24 Correct 40 ms 36436 KB Output is correct
25 Correct 19 ms 32600 KB Output is correct
26 Correct 113 ms 44116 KB Output is correct
27 Correct 39 ms 36444 KB Output is correct
28 Correct 74 ms 48448 KB Output is correct
29 Correct 36 ms 35412 KB Output is correct
30 Correct 83 ms 47020 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 8 ms 31324 KB Output is correct
2 Correct 8 ms 31420 KB Output is correct
3 Correct 9 ms 31324 KB Output is correct
4 Correct 9 ms 31632 KB Output is correct
5 Correct 11 ms 31580 KB Output is correct
6 Correct 10 ms 31836 KB Output is correct
7 Correct 8 ms 31324 KB Output is correct
8 Correct 9 ms 31324 KB Output is correct
9 Correct 11 ms 31836 KB Output is correct
10 Correct 10 ms 31324 KB Output is correct
11 Correct 9 ms 31376 KB Output is correct
12 Correct 9 ms 31324 KB Output is correct
13 Correct 9 ms 31572 KB Output is correct
14 Correct 10 ms 31324 KB Output is correct
15 Correct 10 ms 31428 KB Output is correct
16 Correct 19 ms 32600 KB Output is correct
17 Correct 113 ms 44116 KB Output is correct
18 Correct 39 ms 36444 KB Output is correct
19 Correct 74 ms 48448 KB Output is correct
20 Correct 36 ms 35412 KB Output is correct
21 Correct 83 ms 47020 KB Output is correct
22 Correct 306 ms 57428 KB Output is correct
23 Correct 8 ms 31320 KB Output is correct
24 Correct 9 ms 31320 KB Output is correct
25 Correct 29 ms 63324 KB Output is correct
26 Correct 8 ms 31320 KB Output is correct
27 Correct 10 ms 31544 KB Output is correct
28 Correct 11 ms 32088 KB Output is correct
29 Correct 9 ms 32088 KB Output is correct
30 Correct 178 ms 73328 KB Output is correct
31 Correct 401 ms 114360 KB Output is correct
32 Correct 17 ms 34140 KB Output is correct
33 Correct 20 ms 35676 KB Output is correct
34 Correct 40 ms 36436 KB Output is correct
35 Correct 35 ms 37716 KB Output is correct
36 Correct 281 ms 53824 KB Output is correct
37 Correct 109 ms 43344 KB Output is correct