Submission #942122

# Submission time Handle Problem Language Result Execution time Memory
942122 2024-03-10T09:34:54 Z Mathias Monthly railway pass (LMIO18_menesinis_bilietas) C++14
100 / 100
347 ms 52672 KB
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 5e5+7;
vector<int>g[MAXN];
vector<pair<int,int> >bus;
int sajz[MAXN],res[MAXN],t[MAXN];
map<pair<int,int>, bool> w;
int ans,cnt;
void DFS(int x,int nr){
	t[x]=nr;
	//cout<<x<<' ';
	sajz[nr]++;
	for(auto s:g[x]) if(!t[s]) DFS(s,nr);
}
int main(){
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	int n,m,s1,s2,a,b; char c;
	cin>>n>>m;
	for(int i=1;i<=m;i++){
		cin>>a>>b>>c;
		if(c=='T'){
			g[a].push_back(b); g[b].push_back(a);
		}
		else bus.push_back({a,b});
	}
	for(int i=1;i<=n;i++){
		if(t[i]==0){
			//cout<<"\ni="<<i<<'\n';
			DFS(i,++cnt);
		}
	}
	for(auto k:bus){
		s1=t[k.first]; s2=t[k.second];
		if(s1!=s2 and w[{min(s1,s2),max(s1,s2)}]==0){
			res[s1]++; res[s2]++;
			w[{min(s1,s2),max(s1,s2)}]=1;
		}
	}
	for(int i=1;i<=cnt;i++){
		if(res[i]==cnt-1){
			//cout<<i<<' '<<sajz[i]<<'\n';
			ans+=sajz[i];
		}
	}
	cout<<ans<<'\n';
	return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 232 ms 41300 KB Output is correct
2 Correct 4 ms 15704 KB Output is correct
3 Correct 4 ms 15812 KB Output is correct
4 Correct 6 ms 17500 KB Output is correct
5 Correct 3 ms 15708 KB Output is correct
6 Correct 41 ms 20900 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 17500 KB Output is correct
2 Correct 3 ms 15708 KB Output is correct
3 Correct 4 ms 17756 KB Output is correct
4 Correct 4 ms 17756 KB Output is correct
5 Correct 7 ms 18248 KB Output is correct
6 Correct 239 ms 44748 KB Output is correct
7 Correct 347 ms 52672 KB Output is correct
8 Correct 10 ms 19132 KB Output is correct
9 Correct 16 ms 20192 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 15704 KB Output is correct
2 Correct 4 ms 15812 KB Output is correct
3 Correct 4 ms 17756 KB Output is correct
4 Correct 4 ms 17756 KB Output is correct
5 Correct 7 ms 18248 KB Output is correct
6 Correct 4 ms 17752 KB Output is correct
7 Correct 4 ms 17756 KB Output is correct
8 Correct 4 ms 17756 KB Output is correct
9 Correct 5 ms 18012 KB Output is correct
10 Correct 6 ms 18012 KB Output is correct
11 Correct 6 ms 18008 KB Output is correct
12 Correct 4 ms 17752 KB Output is correct
13 Correct 3 ms 17756 KB Output is correct
14 Correct 7 ms 18268 KB Output is correct
15 Correct 4 ms 15708 KB Output is correct
16 Correct 4 ms 17756 KB Output is correct
17 Correct 4 ms 18008 KB Output is correct
18 Correct 4 ms 17904 KB Output is correct
19 Correct 4 ms 17756 KB Output is correct
20 Correct 5 ms 18012 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 17752 KB Output is correct
2 Correct 4 ms 17756 KB Output is correct
3 Correct 4 ms 17756 KB Output is correct
4 Correct 5 ms 18012 KB Output is correct
5 Correct 6 ms 18012 KB Output is correct
6 Correct 6 ms 18008 KB Output is correct
7 Correct 4 ms 17752 KB Output is correct
8 Correct 3 ms 17756 KB Output is correct
9 Correct 7 ms 18268 KB Output is correct
10 Correct 4 ms 15708 KB Output is correct
11 Correct 4 ms 17756 KB Output is correct
12 Correct 4 ms 18008 KB Output is correct
13 Correct 4 ms 17904 KB Output is correct
14 Correct 4 ms 17756 KB Output is correct
15 Correct 5 ms 18012 KB Output is correct
16 Correct 4 ms 15704 KB Output is correct
17 Correct 4 ms 15812 KB Output is correct
18 Correct 4 ms 17756 KB Output is correct
19 Correct 4 ms 17756 KB Output is correct
20 Correct 7 ms 18248 KB Output is correct
21 Correct 3 ms 15708 KB Output is correct
22 Correct 10 ms 19132 KB Output is correct
23 Correct 16 ms 20192 KB Output is correct
24 Correct 41 ms 20900 KB Output is correct
25 Correct 10 ms 18416 KB Output is correct
26 Correct 95 ms 25872 KB Output is correct
27 Correct 34 ms 20700 KB Output is correct
28 Correct 93 ms 28816 KB Output is correct
29 Correct 30 ms 20432 KB Output is correct
30 Correct 78 ms 28252 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 17752 KB Output is correct
2 Correct 4 ms 17756 KB Output is correct
3 Correct 4 ms 17756 KB Output is correct
4 Correct 5 ms 18012 KB Output is correct
5 Correct 6 ms 18012 KB Output is correct
6 Correct 6 ms 18008 KB Output is correct
7 Correct 4 ms 17752 KB Output is correct
8 Correct 3 ms 17756 KB Output is correct
9 Correct 7 ms 18268 KB Output is correct
10 Correct 4 ms 15708 KB Output is correct
11 Correct 4 ms 17756 KB Output is correct
12 Correct 4 ms 18008 KB Output is correct
13 Correct 4 ms 17904 KB Output is correct
14 Correct 4 ms 17756 KB Output is correct
15 Correct 5 ms 18012 KB Output is correct
16 Correct 10 ms 18416 KB Output is correct
17 Correct 95 ms 25872 KB Output is correct
18 Correct 34 ms 20700 KB Output is correct
19 Correct 93 ms 28816 KB Output is correct
20 Correct 30 ms 20432 KB Output is correct
21 Correct 78 ms 28252 KB Output is correct
22 Correct 232 ms 41300 KB Output is correct
23 Correct 4 ms 15704 KB Output is correct
24 Correct 4 ms 15812 KB Output is correct
25 Correct 6 ms 17500 KB Output is correct
26 Correct 4 ms 17756 KB Output is correct
27 Correct 4 ms 17756 KB Output is correct
28 Correct 7 ms 18248 KB Output is correct
29 Correct 3 ms 15708 KB Output is correct
30 Correct 239 ms 44748 KB Output is correct
31 Correct 347 ms 52672 KB Output is correct
32 Correct 10 ms 19132 KB Output is correct
33 Correct 16 ms 20192 KB Output is correct
34 Correct 41 ms 20900 KB Output is correct
35 Correct 24 ms 20936 KB Output is correct
36 Correct 162 ms 31432 KB Output is correct
37 Correct 92 ms 25872 KB Output is correct