Submission #392447

# Submission time Handle Problem Language Result Execution time Memory
392447 2021-04-21T07:26:44 Z keta_tsimakuridze Monthly railway pass (LMIO18_menesinis_bilietas) C++14
100 / 100
542 ms 64936 KB
#include<bits/stdc++.h>
#define f first
#define int long long
#define s second
using namespace std;
const int N=5e5+5,mod=1e9+7;
int par[N],u,v,n,m,fix[N],comp;
char t;
vector<int>c[N],V[N];
string s;
void merge(int u,int v){
	u=par[u];
	v=par[v];
	if(u==v) return;
	comp--;
	if(c[u].size()<c[v].size()) swap(u,v);
	for(int i=0;i<c[v].size();i++){
		c[u].push_back(c[v][i]);
		par[c[v][i]] = u;
	}
}
 main(){
	// t=1;
	cin>>n>>m;
	for(int i=1;i<=m;i++){
		par[i] = i;
		c[i].push_back(i);
	} comp = n;
	int ans = 0;
	for(int i=1;i<=m;i++){
		cin>>u>>v>>t;
		if(t=='T') merge(u,v);
		else V[u].push_back(v),V[v].push_back(u);
	}
	for(int i=1;i<=n;i++){
		if(par[i]!=i) continue;
		int cnt = 0; 
		for(int j=0;j<c[i].size();j++){
			v=c[i][j];  
			for(int k=0;k<V[v].size();k++){
				if(fix[par[V[v][k] ] ]!= i && par[V[v][k]]!=i) {
					fix[par[V[v][k]]]=i;
					cnt++;
				}
			}
		}
		if(cnt == comp-1) ans+=c[i].size();
	}
	cout<<ans<<endl;
}

Compilation message

menesinis_bilietas.cpp: In function 'void merge(long long int, long long int)':
menesinis_bilietas.cpp:17:15: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   17 |  for(int i=0;i<c[v].size();i++){
      |              ~^~~~~~~~~~~~
menesinis_bilietas.cpp: At global scope:
menesinis_bilietas.cpp:22:7: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   22 |  main(){
      |       ^
menesinis_bilietas.cpp: In function 'int main()':
menesinis_bilietas.cpp:38:16: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   38 |   for(int j=0;j<c[i].size();j++){
      |               ~^~~~~~~~~~~~
menesinis_bilietas.cpp:40:17: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   40 |    for(int k=0;k<V[v].size();k++){
      |                ~^~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 526 ms 55776 KB Output is correct
2 Correct 16 ms 23756 KB Output is correct
3 Correct 17 ms 23832 KB Output is correct
4 Correct 15 ms 23804 KB Output is correct
5 Correct 15 ms 23756 KB Output is correct
6 Correct 157 ms 34292 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 15 ms 23804 KB Output is correct
2 Correct 15 ms 23756 KB Output is correct
3 Correct 15 ms 23784 KB Output is correct
4 Correct 17 ms 23796 KB Output is correct
5 Correct 20 ms 24268 KB Output is correct
6 Correct 300 ms 48184 KB Output is correct
7 Correct 510 ms 64936 KB Output is correct
8 Correct 28 ms 25164 KB Output is correct
9 Correct 39 ms 26084 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 16 ms 23756 KB Output is correct
2 Correct 17 ms 23832 KB Output is correct
3 Correct 15 ms 23784 KB Output is correct
4 Correct 17 ms 23796 KB Output is correct
5 Correct 20 ms 24268 KB Output is correct
6 Correct 15 ms 23708 KB Output is correct
7 Correct 15 ms 23756 KB Output is correct
8 Correct 18 ms 24012 KB Output is correct
9 Correct 20 ms 24272 KB Output is correct
10 Correct 22 ms 24436 KB Output is correct
11 Correct 19 ms 24116 KB Output is correct
12 Correct 16 ms 23788 KB Output is correct
13 Correct 15 ms 23808 KB Output is correct
14 Correct 23 ms 24652 KB Output is correct
15 Correct 15 ms 23756 KB Output is correct
16 Correct 17 ms 23884 KB Output is correct
17 Correct 15 ms 23756 KB Output is correct
18 Correct 16 ms 23884 KB Output is correct
19 Correct 16 ms 23884 KB Output is correct
20 Correct 17 ms 23924 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 15 ms 23708 KB Output is correct
2 Correct 15 ms 23756 KB Output is correct
3 Correct 18 ms 24012 KB Output is correct
4 Correct 20 ms 24272 KB Output is correct
5 Correct 22 ms 24436 KB Output is correct
6 Correct 19 ms 24116 KB Output is correct
7 Correct 16 ms 23788 KB Output is correct
8 Correct 15 ms 23808 KB Output is correct
9 Correct 23 ms 24652 KB Output is correct
10 Correct 15 ms 23756 KB Output is correct
11 Correct 17 ms 23884 KB Output is correct
12 Correct 15 ms 23756 KB Output is correct
13 Correct 16 ms 23884 KB Output is correct
14 Correct 16 ms 23884 KB Output is correct
15 Correct 17 ms 23924 KB Output is correct
16 Correct 16 ms 23756 KB Output is correct
17 Correct 17 ms 23832 KB Output is correct
18 Correct 15 ms 23784 KB Output is correct
19 Correct 17 ms 23796 KB Output is correct
20 Correct 20 ms 24268 KB Output is correct
21 Correct 15 ms 23756 KB Output is correct
22 Correct 28 ms 25164 KB Output is correct
23 Correct 39 ms 26084 KB Output is correct
24 Correct 157 ms 34292 KB Output is correct
25 Correct 37 ms 26188 KB Output is correct
26 Correct 327 ms 52848 KB Output is correct
27 Correct 119 ms 35324 KB Output is correct
28 Correct 148 ms 38984 KB Output is correct
29 Correct 90 ms 32628 KB Output is correct
30 Correct 164 ms 37336 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 15 ms 23708 KB Output is correct
2 Correct 15 ms 23756 KB Output is correct
3 Correct 18 ms 24012 KB Output is correct
4 Correct 20 ms 24272 KB Output is correct
5 Correct 22 ms 24436 KB Output is correct
6 Correct 19 ms 24116 KB Output is correct
7 Correct 16 ms 23788 KB Output is correct
8 Correct 15 ms 23808 KB Output is correct
9 Correct 23 ms 24652 KB Output is correct
10 Correct 15 ms 23756 KB Output is correct
11 Correct 17 ms 23884 KB Output is correct
12 Correct 15 ms 23756 KB Output is correct
13 Correct 16 ms 23884 KB Output is correct
14 Correct 16 ms 23884 KB Output is correct
15 Correct 17 ms 23924 KB Output is correct
16 Correct 37 ms 26188 KB Output is correct
17 Correct 327 ms 52848 KB Output is correct
18 Correct 119 ms 35324 KB Output is correct
19 Correct 148 ms 38984 KB Output is correct
20 Correct 90 ms 32628 KB Output is correct
21 Correct 164 ms 37336 KB Output is correct
22 Correct 526 ms 55776 KB Output is correct
23 Correct 16 ms 23756 KB Output is correct
24 Correct 17 ms 23832 KB Output is correct
25 Correct 15 ms 23804 KB Output is correct
26 Correct 15 ms 23784 KB Output is correct
27 Correct 17 ms 23796 KB Output is correct
28 Correct 20 ms 24268 KB Output is correct
29 Correct 15 ms 23756 KB Output is correct
30 Correct 300 ms 48184 KB Output is correct
31 Correct 510 ms 64936 KB Output is correct
32 Correct 28 ms 25164 KB Output is correct
33 Correct 39 ms 26084 KB Output is correct
34 Correct 157 ms 34292 KB Output is correct
35 Correct 78 ms 29268 KB Output is correct
36 Correct 542 ms 60904 KB Output is correct
37 Correct 279 ms 44724 KB Output is correct