Submission #906442

# Submission time Handle Problem Language Result Execution time Memory
906442 2024-01-14T09:55:57 Z pcc Monthly railway pass (LMIO18_menesinis_bilietas) C++14
100 / 100
639 ms 116064 KB
#include <bits/stdc++.h>
using namespace std;

#define ll long long
#define pll pair<ll,ll>
#define pii pair<int,int>
#define fs first
#define sc second
#define tlll tuple<ll,ll,ll>

const int mxn = 5e5+10;

vector<pii> edges;
int N,M;

bitset<mxn> able;
int dsu[mxn],sz[mxn];
unordered_set<int> paths[mxn];

int root(int k){
	return k == dsu[k]?k:dsu[k] = root(dsu[k]);
}

void onion(int a,int b){
	a = root(a),b = root(b);
	if(a == b)return;
	if(sz[a]<sz[b])swap(a,b);
	dsu[b] = a;
	sz[a] += sz[b];
	return;
}

int main(){
	ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	cin>>N>>M;
	for(int i = 1;i<=N;i++){
		dsu[i] = i,sz[i] = 1;
	}
	for(int i = 0;i<M;i++){
		int a,b;
		char c;
		cin>>a>>b>>c;
		if(c == 'T')onion(a,b);
		else edges.push_back({a,b});
	}
	int gcnt = 0;
	for(auto &i:edges){
		i.fs = root(i.fs);
		i.sc = root(i.sc);
		if(i.fs == i.sc)continue;
		paths[i.fs].insert(i.sc);
		paths[i.sc].insert(i.fs);
	}
	for(int i = 1;i<=N;i++)if(dsu[i] == i)gcnt++;
	for(int i = 1;i<=N;i++){
		if(dsu[i] != i)continue;
		if(paths[i].size()+1 == gcnt)able[i] = true;
	}
	int ans = 0;
	for(int i = 1;i<=N;i++)if(able[root(i)])ans++;
	cout<<ans;
}

Compilation message

menesinis_bilietas.cpp: In function 'int main()':
menesinis_bilietas.cpp:57:24: warning: comparison of integer expressions of different signedness: 'std::unordered_set<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   57 |   if(paths[i].size()+1 == gcnt)able[i] = true;
      |      ~~~~~~~~~~~~~~~~~~^~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 113 ms 38056 KB Output is correct
2 Correct 10 ms 31324 KB Output is correct
3 Correct 9 ms 31440 KB Output is correct
4 Correct 14 ms 31580 KB Output is correct
5 Correct 11 ms 31324 KB Output is correct
6 Correct 34 ms 33708 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 14 ms 31580 KB Output is correct
2 Correct 11 ms 31324 KB Output is correct
3 Correct 11 ms 31324 KB Output is correct
4 Correct 10 ms 31524 KB Output is correct
5 Correct 15 ms 32196 KB Output is correct
6 Correct 485 ms 69732 KB Output is correct
7 Correct 639 ms 116064 KB Output is correct
8 Correct 21 ms 34396 KB Output is correct
9 Correct 26 ms 35544 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 10 ms 31324 KB Output is correct
2 Correct 9 ms 31440 KB Output is correct
3 Correct 11 ms 31324 KB Output is correct
4 Correct 10 ms 31524 KB Output is correct
5 Correct 15 ms 32196 KB Output is correct
6 Correct 11 ms 31528 KB Output is correct
7 Correct 10 ms 31324 KB Output is correct
8 Correct 12 ms 31324 KB Output is correct
9 Correct 11 ms 31324 KB Output is correct
10 Correct 13 ms 31580 KB Output is correct
11 Correct 11 ms 31580 KB Output is correct
12 Correct 12 ms 31324 KB Output is correct
13 Correct 10 ms 31324 KB Output is correct
14 Correct 16 ms 31832 KB Output is correct
15 Correct 10 ms 31324 KB Output is correct
16 Correct 10 ms 31324 KB Output is correct
17 Correct 10 ms 31324 KB Output is correct
18 Correct 11 ms 31324 KB Output is correct
19 Correct 10 ms 31324 KB Output is correct
20 Correct 12 ms 31324 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 11 ms 31528 KB Output is correct
2 Correct 10 ms 31324 KB Output is correct
3 Correct 12 ms 31324 KB Output is correct
4 Correct 11 ms 31324 KB Output is correct
5 Correct 13 ms 31580 KB Output is correct
6 Correct 11 ms 31580 KB Output is correct
7 Correct 12 ms 31324 KB Output is correct
8 Correct 10 ms 31324 KB Output is correct
9 Correct 16 ms 31832 KB Output is correct
10 Correct 10 ms 31324 KB Output is correct
11 Correct 10 ms 31324 KB Output is correct
12 Correct 10 ms 31324 KB Output is correct
13 Correct 11 ms 31324 KB Output is correct
14 Correct 10 ms 31324 KB Output is correct
15 Correct 12 ms 31324 KB Output is correct
16 Correct 10 ms 31324 KB Output is correct
17 Correct 9 ms 31440 KB Output is correct
18 Correct 11 ms 31324 KB Output is correct
19 Correct 10 ms 31524 KB Output is correct
20 Correct 15 ms 32196 KB Output is correct
21 Correct 11 ms 31324 KB Output is correct
22 Correct 21 ms 34396 KB Output is correct
23 Correct 26 ms 35544 KB Output is correct
24 Correct 34 ms 33708 KB Output is correct
25 Correct 14 ms 32092 KB Output is correct
26 Correct 80 ms 39804 KB Output is correct
27 Correct 44 ms 34964 KB Output is correct
28 Correct 96 ms 44604 KB Output is correct
29 Correct 37 ms 33744 KB Output is correct
30 Correct 96 ms 43008 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 11 ms 31528 KB Output is correct
2 Correct 10 ms 31324 KB Output is correct
3 Correct 12 ms 31324 KB Output is correct
4 Correct 11 ms 31324 KB Output is correct
5 Correct 13 ms 31580 KB Output is correct
6 Correct 11 ms 31580 KB Output is correct
7 Correct 12 ms 31324 KB Output is correct
8 Correct 10 ms 31324 KB Output is correct
9 Correct 16 ms 31832 KB Output is correct
10 Correct 10 ms 31324 KB Output is correct
11 Correct 10 ms 31324 KB Output is correct
12 Correct 10 ms 31324 KB Output is correct
13 Correct 11 ms 31324 KB Output is correct
14 Correct 10 ms 31324 KB Output is correct
15 Correct 12 ms 31324 KB Output is correct
16 Correct 14 ms 32092 KB Output is correct
17 Correct 80 ms 39804 KB Output is correct
18 Correct 44 ms 34964 KB Output is correct
19 Correct 96 ms 44604 KB Output is correct
20 Correct 37 ms 33744 KB Output is correct
21 Correct 96 ms 43008 KB Output is correct
22 Correct 113 ms 38056 KB Output is correct
23 Correct 10 ms 31324 KB Output is correct
24 Correct 9 ms 31440 KB Output is correct
25 Correct 14 ms 31580 KB Output is correct
26 Correct 11 ms 31324 KB Output is correct
27 Correct 10 ms 31524 KB Output is correct
28 Correct 15 ms 32196 KB Output is correct
29 Correct 11 ms 31324 KB Output is correct
30 Correct 485 ms 69732 KB Output is correct
31 Correct 639 ms 116064 KB Output is correct
32 Correct 21 ms 34396 KB Output is correct
33 Correct 26 ms 35544 KB Output is correct
34 Correct 34 ms 33708 KB Output is correct
35 Correct 28 ms 33748 KB Output is correct
36 Correct 110 ms 45508 KB Output is correct
37 Correct 46 ms 34388 KB Output is correct