Submission #382249

# Submission time Handle Problem Language Result Execution time Memory
382249 2021-03-26T20:24:13 Z fadi57 Monthly railway pass (LMIO18_menesinis_bilietas) C++14
100 / 100
950 ms 92636 KB
#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
const ll mx=500006;
const int mod= 1e9+7 ;
const ll inf=0;



//***while there is life there is hope
int n,m;

int siz[mx];int par[mx];vector<pair<int,int>>adj[mx];
void init(){

for(int i=1;i<=n;i++){
    par[i]=i;
    siz[i]=1;
}

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

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

 }
}
void uni(int x,int y){

    int a=root(x);
    int b=root(y);
if(siz[a]<siz[b]){swap(a,b);}

par[b]=a;
siz[a]+=siz[b];

 }
 int isa(char x){

 return (x=='A');
 }
 int a[mx];

int main() {
cin>>n>>m;
int sec=0;
init();
for(int i=0;i<m;i++){
int x,y;char t;
cin>>x>>y>>t;



    adj[x].push_back({y,isa(t)});
    adj[y].push_back({x,isa(t)});
  if(isa(t)==0){
    uni(x,y);
  }
}
set<int>comp;
vector<int>v[n+1];
for(int i=1;i<=n;i++){
   //cout<<par[i]<<" "<<siz[i]<<endl;
   comp.insert(root(i));
   v[root(i)].push_back(i);
}
int ans=0;

for(int i = 1 ; i <= n ; ++i)
	{

	    if(!v[i].size()){continue;}
	    set<int>s;s.insert(i);
	    for(auto it:v[i]){
            for(auto itt:adj[it]){
                s.insert(root(itt.first));
            }
	    }ans+=(comp.size()==s.size())*v[i].size();
	}cout<<ans;



}

Compilation message

menesinis_bilietas.cpp: In function 'int main()':
menesinis_bilietas.cpp:50:5: warning: unused variable 'sec' [-Wunused-variable]
   50 | int sec=0;
      |     ^~~
# Verdict Execution time Memory Grader output
1 Correct 748 ms 39972 KB Output is correct
2 Correct 8 ms 12140 KB Output is correct
3 Correct 9 ms 12140 KB Output is correct
4 Correct 179 ms 63668 KB Output is correct
5 Correct 12 ms 13548 KB Output is correct
6 Correct 192 ms 17920 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 179 ms 63668 KB Output is correct
2 Correct 12 ms 13548 KB Output is correct
3 Correct 10 ms 12140 KB Output is correct
4 Correct 9 ms 12140 KB Output is correct
5 Correct 15 ms 12524 KB Output is correct
6 Correct 433 ms 26552 KB Output is correct
7 Correct 950 ms 92636 KB Output is correct
8 Correct 29 ms 15212 KB Output is correct
9 Correct 41 ms 15596 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 8 ms 12140 KB Output is correct
2 Correct 9 ms 12140 KB Output is correct
3 Correct 10 ms 12140 KB Output is correct
4 Correct 9 ms 12140 KB Output is correct
5 Correct 15 ms 12524 KB Output is correct
6 Correct 8 ms 12140 KB Output is correct
7 Correct 8 ms 12140 KB Output is correct
8 Correct 10 ms 12268 KB Output is correct
9 Correct 12 ms 12268 KB Output is correct
10 Correct 15 ms 12396 KB Output is correct
11 Correct 14 ms 12396 KB Output is correct
12 Correct 9 ms 12140 KB Output is correct
13 Correct 9 ms 12268 KB Output is correct
14 Correct 17 ms 12672 KB Output is correct
15 Correct 8 ms 12140 KB Output is correct
16 Correct 10 ms 12140 KB Output is correct
17 Correct 8 ms 12140 KB Output is correct
18 Correct 10 ms 12140 KB Output is correct
19 Correct 11 ms 12140 KB Output is correct
20 Correct 11 ms 12268 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 8 ms 12140 KB Output is correct
2 Correct 8 ms 12140 KB Output is correct
3 Correct 10 ms 12268 KB Output is correct
4 Correct 12 ms 12268 KB Output is correct
5 Correct 15 ms 12396 KB Output is correct
6 Correct 14 ms 12396 KB Output is correct
7 Correct 9 ms 12140 KB Output is correct
8 Correct 9 ms 12268 KB Output is correct
9 Correct 17 ms 12672 KB Output is correct
10 Correct 8 ms 12140 KB Output is correct
11 Correct 10 ms 12140 KB Output is correct
12 Correct 8 ms 12140 KB Output is correct
13 Correct 10 ms 12140 KB Output is correct
14 Correct 11 ms 12140 KB Output is correct
15 Correct 11 ms 12268 KB Output is correct
16 Correct 8 ms 12140 KB Output is correct
17 Correct 9 ms 12140 KB Output is correct
18 Correct 10 ms 12140 KB Output is correct
19 Correct 9 ms 12140 KB Output is correct
20 Correct 15 ms 12524 KB Output is correct
21 Correct 12 ms 13548 KB Output is correct
22 Correct 29 ms 15212 KB Output is correct
23 Correct 41 ms 15596 KB Output is correct
24 Correct 192 ms 17920 KB Output is correct
25 Correct 31 ms 13292 KB Output is correct
26 Correct 340 ms 23020 KB Output is correct
27 Correct 124 ms 16636 KB Output is correct
28 Correct 176 ms 18028 KB Output is correct
29 Correct 95 ms 15804 KB Output is correct
30 Correct 190 ms 17900 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 8 ms 12140 KB Output is correct
2 Correct 8 ms 12140 KB Output is correct
3 Correct 10 ms 12268 KB Output is correct
4 Correct 12 ms 12268 KB Output is correct
5 Correct 15 ms 12396 KB Output is correct
6 Correct 14 ms 12396 KB Output is correct
7 Correct 9 ms 12140 KB Output is correct
8 Correct 9 ms 12268 KB Output is correct
9 Correct 17 ms 12672 KB Output is correct
10 Correct 8 ms 12140 KB Output is correct
11 Correct 10 ms 12140 KB Output is correct
12 Correct 8 ms 12140 KB Output is correct
13 Correct 10 ms 12140 KB Output is correct
14 Correct 11 ms 12140 KB Output is correct
15 Correct 11 ms 12268 KB Output is correct
16 Correct 31 ms 13292 KB Output is correct
17 Correct 340 ms 23020 KB Output is correct
18 Correct 124 ms 16636 KB Output is correct
19 Correct 176 ms 18028 KB Output is correct
20 Correct 95 ms 15804 KB Output is correct
21 Correct 190 ms 17900 KB Output is correct
22 Correct 748 ms 39972 KB Output is correct
23 Correct 8 ms 12140 KB Output is correct
24 Correct 9 ms 12140 KB Output is correct
25 Correct 179 ms 63668 KB Output is correct
26 Correct 10 ms 12140 KB Output is correct
27 Correct 9 ms 12140 KB Output is correct
28 Correct 15 ms 12524 KB Output is correct
29 Correct 12 ms 13548 KB Output is correct
30 Correct 433 ms 26552 KB Output is correct
31 Correct 950 ms 92636 KB Output is correct
32 Correct 29 ms 15212 KB Output is correct
33 Correct 41 ms 15596 KB Output is correct
34 Correct 192 ms 17920 KB Output is correct
35 Correct 101 ms 15644 KB Output is correct
36 Correct 587 ms 28476 KB Output is correct
37 Correct 358 ms 26988 KB Output is correct