#include <algorithm>
#include <bitset>
#include <cassert>
#include <chrono>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <limits>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <ratio>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
#include <climits>
#define ll long long
#define ld long double
#define mp make_pair
#define pb push_back
#define in insert
#define vll vector<ll>
#define endl "\n"
#define pll pair<ll,ll>
#define f first
#define s second
#define FOR(i,a,b) for(int i=(a),_b=(b); i<=_b; i++)
#define int ll
#define sz(x) (ll)x.size()
#define all(x) (x.begin(),x.end())
using namespace std;
const ll INF = 1e12;
const ll N =(5e5+5); // TODO : change value as per problem
const ll MOD = 1e9+7;
vector<int> adj[N];
set<int>adj2[N];
vector<pair<int,int>> bus;
int col[N];
int nodes[N];
int gg;
void dfs(int u,int c){
col[u] = c;
gg++;
// cout << u << " ";
for(auto v:adj[u]){
if(col[v] == 0){
dfs(v,c);
}
}
}
void solve(){
int n,m;
cin >> n >> m;
for(int i =1;i<=m;i++){
int u,v;
char ch;
cin >> u >> v >> ch;
if(ch == 'A') {
bus.pb({u,v});
}
else{
adj[u].pb(v);
adj[v].pb(u);
}
}
int cur = 0;
for(int i =1;i<=n;i++){
if(col[i] == 0){
gg = 0;
cur++;
dfs(i,cur);
nodes[cur] = gg;
// cout << endl;
}
}
// for(int i =1;i<=n;i++) cout << col[i] << " ";cout << endl;
for(int i =0;i<bus.size();i++){
int u = bus[i].f,v = bus[i].s;
if(col[u] == col[v]) continue;
adj2[col[u]].in(col[v]);
adj2[col[v]].in(col[u]);
}
int ans = 0;
for(int i =1;i<=cur;i++){
int s = adj2[i].size();
// cout << "Colour : " << i << " -> ";
// for(auto j:adj2[i]) cout << j << " ";
// cout << endl;
if(s == (cur-1)) {
// cout << "YAY\n";
// cout << i << endl;
ans += nodes[i];
}
}
cout << ans << endl;
}
signed main(){
ios_base::sync_with_stdio(0);
cin.tie(NULL);
// freopen(".in","r",stdin);freopen(".out","w",stdout);
ll tt=1;
// cin >> tt;
while(tt--){
solve();
}
}
Compilation message
menesinis_bilietas.cpp: In function 'void solve()':
menesinis_bilietas.cpp:93:16: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int i =0;i<bus.size();i++){
~^~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
404 ms |
64632 KB |
Output is correct |
2 |
Correct |
21 ms |
35584 KB |
Output is correct |
3 |
Correct |
21 ms |
35584 KB |
Output is correct |
4 |
Correct |
28 ms |
42872 KB |
Output is correct |
5 |
Correct |
21 ms |
35712 KB |
Output is correct |
6 |
Correct |
71 ms |
43000 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
28 ms |
42872 KB |
Output is correct |
2 |
Correct |
25 ms |
35584 KB |
Output is correct |
3 |
Correct |
22 ms |
35712 KB |
Output is correct |
4 |
Correct |
30 ms |
36472 KB |
Output is correct |
5 |
Correct |
21 ms |
35712 KB |
Output is correct |
6 |
Correct |
736 ms |
76812 KB |
Output is correct |
7 |
Correct |
679 ms |
92624 KB |
Output is correct |
8 |
Correct |
33 ms |
37624 KB |
Output is correct |
9 |
Correct |
38 ms |
39284 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
21 ms |
35584 KB |
Output is correct |
2 |
Correct |
21 ms |
35584 KB |
Output is correct |
3 |
Correct |
22 ms |
35704 KB |
Output is correct |
4 |
Correct |
26 ms |
35840 KB |
Output is correct |
5 |
Correct |
23 ms |
36088 KB |
Output is correct |
6 |
Correct |
24 ms |
35960 KB |
Output is correct |
7 |
Correct |
27 ms |
35584 KB |
Output is correct |
8 |
Correct |
21 ms |
35584 KB |
Output is correct |
9 |
Correct |
30 ms |
36108 KB |
Output is correct |
10 |
Correct |
21 ms |
35584 KB |
Output is correct |
11 |
Correct |
27 ms |
35712 KB |
Output is correct |
12 |
Correct |
24 ms |
35584 KB |
Output is correct |
13 |
Correct |
27 ms |
35704 KB |
Output is correct |
14 |
Correct |
21 ms |
35584 KB |
Output is correct |
15 |
Correct |
22 ms |
35724 KB |
Output is correct |
16 |
Correct |
21 ms |
35584 KB |
Output is correct |
17 |
Correct |
21 ms |
35584 KB |
Output is correct |
18 |
Correct |
25 ms |
35584 KB |
Output is correct |
19 |
Correct |
22 ms |
35712 KB |
Output is correct |
20 |
Correct |
30 ms |
36472 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
21 ms |
35584 KB |
Output is correct |
2 |
Correct |
21 ms |
35584 KB |
Output is correct |
3 |
Correct |
22 ms |
35704 KB |
Output is correct |
4 |
Correct |
26 ms |
35840 KB |
Output is correct |
5 |
Correct |
23 ms |
36088 KB |
Output is correct |
6 |
Correct |
24 ms |
35960 KB |
Output is correct |
7 |
Correct |
27 ms |
35584 KB |
Output is correct |
8 |
Correct |
21 ms |
35584 KB |
Output is correct |
9 |
Correct |
30 ms |
36108 KB |
Output is correct |
10 |
Correct |
21 ms |
35584 KB |
Output is correct |
11 |
Correct |
27 ms |
35712 KB |
Output is correct |
12 |
Correct |
24 ms |
35584 KB |
Output is correct |
13 |
Correct |
27 ms |
35704 KB |
Output is correct |
14 |
Correct |
21 ms |
35584 KB |
Output is correct |
15 |
Correct |
22 ms |
35724 KB |
Output is correct |
16 |
Correct |
30 ms |
36500 KB |
Output is correct |
17 |
Correct |
168 ms |
48008 KB |
Output is correct |
18 |
Correct |
71 ms |
41200 KB |
Output is correct |
19 |
Correct |
209 ms |
52072 KB |
Output is correct |
20 |
Correct |
72 ms |
39188 KB |
Output is correct |
21 |
Correct |
180 ms |
50764 KB |
Output is correct |
22 |
Correct |
21 ms |
35584 KB |
Output is correct |
23 |
Correct |
21 ms |
35584 KB |
Output is correct |
24 |
Correct |
25 ms |
35584 KB |
Output is correct |
25 |
Correct |
22 ms |
35712 KB |
Output is correct |
26 |
Correct |
30 ms |
36472 KB |
Output is correct |
27 |
Correct |
21 ms |
35712 KB |
Output is correct |
28 |
Correct |
33 ms |
37624 KB |
Output is correct |
29 |
Correct |
38 ms |
39284 KB |
Output is correct |
30 |
Correct |
71 ms |
43000 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
21 ms |
35584 KB |
Output is correct |
2 |
Correct |
21 ms |
35584 KB |
Output is correct |
3 |
Correct |
22 ms |
35704 KB |
Output is correct |
4 |
Correct |
26 ms |
35840 KB |
Output is correct |
5 |
Correct |
23 ms |
36088 KB |
Output is correct |
6 |
Correct |
24 ms |
35960 KB |
Output is correct |
7 |
Correct |
27 ms |
35584 KB |
Output is correct |
8 |
Correct |
21 ms |
35584 KB |
Output is correct |
9 |
Correct |
30 ms |
36108 KB |
Output is correct |
10 |
Correct |
21 ms |
35584 KB |
Output is correct |
11 |
Correct |
27 ms |
35712 KB |
Output is correct |
12 |
Correct |
24 ms |
35584 KB |
Output is correct |
13 |
Correct |
27 ms |
35704 KB |
Output is correct |
14 |
Correct |
21 ms |
35584 KB |
Output is correct |
15 |
Correct |
22 ms |
35724 KB |
Output is correct |
16 |
Correct |
30 ms |
36500 KB |
Output is correct |
17 |
Correct |
168 ms |
48008 KB |
Output is correct |
18 |
Correct |
71 ms |
41200 KB |
Output is correct |
19 |
Correct |
209 ms |
52072 KB |
Output is correct |
20 |
Correct |
72 ms |
39188 KB |
Output is correct |
21 |
Correct |
180 ms |
50764 KB |
Output is correct |
22 |
Correct |
404 ms |
64632 KB |
Output is correct |
23 |
Correct |
21 ms |
35584 KB |
Output is correct |
24 |
Correct |
21 ms |
35584 KB |
Output is correct |
25 |
Correct |
28 ms |
42872 KB |
Output is correct |
26 |
Correct |
25 ms |
35584 KB |
Output is correct |
27 |
Correct |
22 ms |
35712 KB |
Output is correct |
28 |
Correct |
30 ms |
36472 KB |
Output is correct |
29 |
Correct |
21 ms |
35712 KB |
Output is correct |
30 |
Correct |
736 ms |
76812 KB |
Output is correct |
31 |
Correct |
679 ms |
92624 KB |
Output is correct |
32 |
Correct |
62 ms |
39660 KB |
Output is correct |
33 |
Correct |
314 ms |
55124 KB |
Output is correct |
34 |
Correct |
180 ms |
46712 KB |
Output is correct |
35 |
Correct |
33 ms |
37624 KB |
Output is correct |
36 |
Correct |
38 ms |
39284 KB |
Output is correct |
37 |
Correct |
71 ms |
43000 KB |
Output is correct |