답안 #304900

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
304900 2020-09-22T07:36:01 Z computerbox Monthly railway pass (LMIO18_menesinis_bilietas) C++14
100 / 100
704 ms 80924 KB
#include <bits/stdc++.h>
#define FLASH ios_base::sync_with_stdio(0);
#define ll long long
#define debt(x,y)cout<<"#x = "<<(x)<<" and "<<"#y = "<<(y)<<endl;
#define deb(x)cout<<"#x = "<<(x)<<endl;
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(), (x).end()
#define endl "\n"
#define arr(a,n) for(ll i=1;i<=n;i++) cout<<a[i]<<" "; cout << "\n";
#define vecc(a,n) for(ll i=0;i<n;i++) cout<<a[i]<<" "; cout << "\n";


using namespace std;


ll n,m;
struct edge
{
  ll x,y;	
};



vector<edge>bus;
set<ll>adj[500010];

ll par[500010];
ll rankk[500010];

void make_set(ll n)
{
  for(ll i=0;i<=n;i++){rankk[i]=1;par[i]=i;}	
}

ll findd(ll v)
{
 while(par[v]!=v)
 {
  par[v]=par[par[v]];
  v=par[v];
 }	
 return v;
}


void make_union(ll a,ll b)
{
  a=findd(a);b=findd(b);
  if(a!=b)
  {
	if(rankk[a]>rankk[b])swap(a,b);
	rankk[b]+=rankk[a];
	par[a]=par[b];  
  }	
}


int main(){
FLASH;
cin>>n>>m;
make_set(n);
for(ll i=1;i<=m;i++)
{
 ll x,y;
 char z;
 cin>>x>>y>>z;
 if(z=='T')
 {
  make_union(x,y); 
 }
 else bus.pb({x,y});	
	
}

for(auto i:bus)
{
  if(findd(i.x)!=findd(i.y))
  {
    adj[findd(i.x)].insert(findd(i.y));
    adj[findd(i.y)].insert(findd(i.x));
  }	
}
ll cnt=0;
for(ll i=1;i<=n;i++)
{
  ll p=findd(i);
  if(p==i)
  {
    cnt++;
  }	
}


ll ans=0;
for(ll i=1;i<=n;i++)
{
  ll p=findd(i);
  if(p==i)
  {
	ll sz=(ll)adj[i].size();
	if(sz==cnt-1)ans+=rankk[i];  
  }	
}

cout<<ans<<endl;
return 0;
} 
# 결과 실행 시간 메모리 Grader output
1 Correct 185 ms 35320 KB Output is correct
2 Correct 17 ms 23808 KB Output is correct
3 Correct 17 ms 23808 KB Output is correct
4 Correct 23 ms 31240 KB Output is correct
5 Correct 17 ms 24064 KB Output is correct
6 Correct 58 ms 26360 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 23 ms 31240 KB Output is correct
2 Correct 16 ms 23808 KB Output is correct
3 Correct 17 ms 23936 KB Output is correct
4 Correct 21 ms 24704 KB Output is correct
5 Correct 17 ms 24064 KB Output is correct
6 Correct 601 ms 65108 KB Output is correct
7 Correct 704 ms 80924 KB Output is correct
8 Correct 26 ms 25856 KB Output is correct
9 Correct 37 ms 27548 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 16 ms 23808 KB Output is correct
2 Correct 16 ms 23808 KB Output is correct
3 Correct 17 ms 23936 KB Output is correct
4 Correct 18 ms 24064 KB Output is correct
5 Correct 19 ms 24448 KB Output is correct
6 Correct 19 ms 24192 KB Output is correct
7 Correct 16 ms 23936 KB Output is correct
8 Correct 16 ms 23936 KB Output is correct
9 Correct 21 ms 24320 KB Output is correct
10 Correct 16 ms 23808 KB Output is correct
11 Correct 17 ms 23936 KB Output is correct
12 Correct 16 ms 23808 KB Output is correct
13 Correct 18 ms 24064 KB Output is correct
14 Correct 16 ms 23936 KB Output is correct
15 Correct 17 ms 23936 KB Output is correct
16 Correct 17 ms 23808 KB Output is correct
17 Correct 17 ms 23808 KB Output is correct
18 Correct 16 ms 23808 KB Output is correct
19 Correct 17 ms 23936 KB Output is correct
20 Correct 21 ms 24704 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 16 ms 23808 KB Output is correct
2 Correct 16 ms 23808 KB Output is correct
3 Correct 17 ms 23936 KB Output is correct
4 Correct 18 ms 24064 KB Output is correct
5 Correct 19 ms 24448 KB Output is correct
6 Correct 19 ms 24192 KB Output is correct
7 Correct 16 ms 23936 KB Output is correct
8 Correct 16 ms 23936 KB Output is correct
9 Correct 21 ms 24320 KB Output is correct
10 Correct 16 ms 23808 KB Output is correct
11 Correct 17 ms 23936 KB Output is correct
12 Correct 16 ms 23808 KB Output is correct
13 Correct 18 ms 24064 KB Output is correct
14 Correct 16 ms 23936 KB Output is correct
15 Correct 17 ms 23936 KB Output is correct
16 Correct 26 ms 24832 KB Output is correct
17 Correct 177 ms 36036 KB Output is correct
18 Correct 83 ms 29548 KB Output is correct
19 Correct 268 ms 40288 KB Output is correct
20 Correct 67 ms 27372 KB Output is correct
21 Correct 203 ms 37984 KB Output is correct
22 Correct 17 ms 23808 KB Output is correct
23 Correct 17 ms 23808 KB Output is correct
24 Correct 16 ms 23808 KB Output is correct
25 Correct 17 ms 23936 KB Output is correct
26 Correct 21 ms 24704 KB Output is correct
27 Correct 17 ms 24064 KB Output is correct
28 Correct 26 ms 25856 KB Output is correct
29 Correct 37 ms 27548 KB Output is correct
30 Correct 58 ms 26360 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 16 ms 23808 KB Output is correct
2 Correct 16 ms 23808 KB Output is correct
3 Correct 17 ms 23936 KB Output is correct
4 Correct 18 ms 24064 KB Output is correct
5 Correct 19 ms 24448 KB Output is correct
6 Correct 19 ms 24192 KB Output is correct
7 Correct 16 ms 23936 KB Output is correct
8 Correct 16 ms 23936 KB Output is correct
9 Correct 21 ms 24320 KB Output is correct
10 Correct 16 ms 23808 KB Output is correct
11 Correct 17 ms 23936 KB Output is correct
12 Correct 16 ms 23808 KB Output is correct
13 Correct 18 ms 24064 KB Output is correct
14 Correct 16 ms 23936 KB Output is correct
15 Correct 17 ms 23936 KB Output is correct
16 Correct 26 ms 24832 KB Output is correct
17 Correct 177 ms 36036 KB Output is correct
18 Correct 83 ms 29548 KB Output is correct
19 Correct 268 ms 40288 KB Output is correct
20 Correct 67 ms 27372 KB Output is correct
21 Correct 203 ms 37984 KB Output is correct
22 Correct 185 ms 35320 KB Output is correct
23 Correct 17 ms 23808 KB Output is correct
24 Correct 17 ms 23808 KB Output is correct
25 Correct 23 ms 31240 KB Output is correct
26 Correct 16 ms 23808 KB Output is correct
27 Correct 17 ms 23936 KB Output is correct
28 Correct 21 ms 24704 KB Output is correct
29 Correct 17 ms 24064 KB Output is correct
30 Correct 601 ms 65108 KB Output is correct
31 Correct 704 ms 80924 KB Output is correct
32 Correct 48 ms 27344 KB Output is correct
33 Correct 330 ms 41380 KB Output is correct
34 Correct 87 ms 30200 KB Output is correct
35 Correct 26 ms 25856 KB Output is correct
36 Correct 37 ms 27548 KB Output is correct
37 Correct 58 ms 26360 KB Output is correct