답안 #382155

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
382155 2021-03-26T15:29:50 Z MohamedAhmed04 Monthly railway pass (LMIO18_menesinis_bilietas) C++14
100 / 100
738 ms 93736 KB
#include <bits/stdc++.h>

using namespace std ;

const int MAX = 5e5 + 10 ;

int arr[MAX] ;
int n , m ;

vector< vector< pair<int , char> > >adj(MAX) ;

int par[MAX] , sz[MAX] ;
vector<int>v[MAX] ;

void init()
{
	for(int i = 1 ; i <= n ; ++i)
		par[i] = i , sz[i] = 1 ;
}

int root(int node)
{
	if(par[node] == node)
		return node ;
	return (par[node] = root(par[node])) ;
}

void Union(int x , int y)
{
	int a = root(x) ;
	int b = root(y) ;
	if(a == b)
		return ;
	if(sz[a] < sz[b])
		swap(a , b) ;
	par[b] = a ;
	sz[a] += sz[b] ;
}

int main()
{
	ios_base::sync_with_stdio(0) ;
	cin.tie(0) ;
	cin>>n>>m ;
	init() ;
	for(int i = 0 ; i < m ; ++i)
	{
		int x , y ;
		char c ;
		cin>>x>>y>>c ;
		if(c == 'T')
			Union(x , y) ;
		adj[x].emplace_back(y , c) ;
		adj[y].emplace_back(x , c) ;
	}
	set<int>s ;
	for(int i = 1 ; i <= n ; ++i)
		s.insert(root(i)) , v[root(i)].push_back(i) ;
	set<int>s2 ;
	int ans = 0 ;
	for(int i = 1 ; i <= n ; ++i)
	{
		if(!v[i].size())
			continue ;
		s2.clear() ;
		s2.insert(i) ;
		for(auto &node : v[i])
		{
			for(auto &child : adj[node])
				s2.insert(root(child.first)) ;
		}
		ans += (s.size() == s2.size()) * v[i].size() ;
	}
	return cout<<ans<<"\n" , 0 ;
}		
# 결과 실행 시간 메모리 Grader output
1 Correct 434 ms 43488 KB Output is correct
2 Correct 15 ms 23788 KB Output is correct
3 Correct 15 ms 23916 KB Output is correct
4 Correct 171 ms 64236 KB Output is correct
5 Correct 18 ms 24940 KB Output is correct
6 Correct 74 ms 28780 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 171 ms 64236 KB Output is correct
2 Correct 18 ms 24940 KB Output is correct
3 Correct 15 ms 23788 KB Output is correct
4 Correct 15 ms 24064 KB Output is correct
5 Correct 22 ms 24172 KB Output is correct
6 Correct 269 ms 36664 KB Output is correct
7 Correct 738 ms 93736 KB Output is correct
8 Correct 28 ms 26476 KB Output is correct
9 Correct 44 ms 26732 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 15 ms 23788 KB Output is correct
2 Correct 15 ms 23916 KB Output is correct
3 Correct 15 ms 23788 KB Output is correct
4 Correct 15 ms 24064 KB Output is correct
5 Correct 22 ms 24172 KB Output is correct
6 Correct 16 ms 23788 KB Output is correct
7 Correct 15 ms 23788 KB Output is correct
8 Correct 16 ms 23916 KB Output is correct
9 Correct 17 ms 24044 KB Output is correct
10 Correct 18 ms 24044 KB Output is correct
11 Correct 17 ms 24044 KB Output is correct
12 Correct 15 ms 24060 KB Output is correct
13 Correct 15 ms 23788 KB Output is correct
14 Correct 20 ms 24172 KB Output is correct
15 Correct 15 ms 23788 KB Output is correct
16 Correct 16 ms 23916 KB Output is correct
17 Correct 15 ms 23788 KB Output is correct
18 Correct 16 ms 23916 KB Output is correct
19 Correct 16 ms 23916 KB Output is correct
20 Correct 16 ms 23916 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 16 ms 23788 KB Output is correct
2 Correct 15 ms 23788 KB Output is correct
3 Correct 16 ms 23916 KB Output is correct
4 Correct 17 ms 24044 KB Output is correct
5 Correct 18 ms 24044 KB Output is correct
6 Correct 17 ms 24044 KB Output is correct
7 Correct 15 ms 24060 KB Output is correct
8 Correct 15 ms 23788 KB Output is correct
9 Correct 20 ms 24172 KB Output is correct
10 Correct 15 ms 23788 KB Output is correct
11 Correct 16 ms 23916 KB Output is correct
12 Correct 15 ms 23788 KB Output is correct
13 Correct 16 ms 23916 KB Output is correct
14 Correct 16 ms 23916 KB Output is correct
15 Correct 16 ms 23916 KB Output is correct
16 Correct 15 ms 23788 KB Output is correct
17 Correct 15 ms 23916 KB Output is correct
18 Correct 15 ms 23788 KB Output is correct
19 Correct 15 ms 24064 KB Output is correct
20 Correct 22 ms 24172 KB Output is correct
21 Correct 18 ms 24940 KB Output is correct
22 Correct 28 ms 26476 KB Output is correct
23 Correct 44 ms 26732 KB Output is correct
24 Correct 74 ms 28780 KB Output is correct
25 Correct 26 ms 24812 KB Output is correct
26 Correct 217 ms 33772 KB Output is correct
27 Correct 66 ms 27628 KB Output is correct
28 Correct 109 ms 29140 KB Output is correct
29 Correct 57 ms 26988 KB Output is correct
30 Correct 118 ms 28780 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 16 ms 23788 KB Output is correct
2 Correct 15 ms 23788 KB Output is correct
3 Correct 16 ms 23916 KB Output is correct
4 Correct 17 ms 24044 KB Output is correct
5 Correct 18 ms 24044 KB Output is correct
6 Correct 17 ms 24044 KB Output is correct
7 Correct 15 ms 24060 KB Output is correct
8 Correct 15 ms 23788 KB Output is correct
9 Correct 20 ms 24172 KB Output is correct
10 Correct 15 ms 23788 KB Output is correct
11 Correct 16 ms 23916 KB Output is correct
12 Correct 15 ms 23788 KB Output is correct
13 Correct 16 ms 23916 KB Output is correct
14 Correct 16 ms 23916 KB Output is correct
15 Correct 16 ms 23916 KB Output is correct
16 Correct 26 ms 24812 KB Output is correct
17 Correct 217 ms 33772 KB Output is correct
18 Correct 66 ms 27628 KB Output is correct
19 Correct 109 ms 29140 KB Output is correct
20 Correct 57 ms 26988 KB Output is correct
21 Correct 118 ms 28780 KB Output is correct
22 Correct 434 ms 43488 KB Output is correct
23 Correct 15 ms 23788 KB Output is correct
24 Correct 15 ms 23916 KB Output is correct
25 Correct 171 ms 64236 KB Output is correct
26 Correct 15 ms 23788 KB Output is correct
27 Correct 15 ms 24064 KB Output is correct
28 Correct 22 ms 24172 KB Output is correct
29 Correct 18 ms 24940 KB Output is correct
30 Correct 269 ms 36664 KB Output is correct
31 Correct 738 ms 93736 KB Output is correct
32 Correct 28 ms 26476 KB Output is correct
33 Correct 44 ms 26732 KB Output is correct
34 Correct 74 ms 28780 KB Output is correct
35 Correct 61 ms 26220 KB Output is correct
36 Correct 445 ms 37100 KB Output is correct
37 Correct 255 ms 33388 KB Output is correct