This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
#define fastio ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
#define debug(x) cout << "Line " << __LINE__ << ", " << #x << " is " << x << endl
#define all(x) x.begin(), x.end()
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define ll long long
#define ull unsigned long long
#define pll pair<ll, ll>
#define pii pair<ll, ll>
#define ld long double
#define nl '\n'
#define tb '\t'
#define sp ' '
#define sqr(x) (x)*(x)
#define arr3 array<ll, 3>
#define arr4 array<ll, 4>
using namespace std;
const ll MX=500007, MOD=1000000007, BLOCK=333, INF=1e9+7, LG=62, KEY1=177013, KEY2=353707;
const ll INFF=1000000000000000007;
const ld ERR=1e-6;
int N, M, group[MX], sz[MX], cnt, ans;
vector<int> bus[MX], tr[MX];
set<int> adj[MX];
void DFS(int x){
group[x]=cnt;
sz[cnt]++;
for(int i:tr[x]){
if(group[i])
continue;
DFS(i);
}
}
int main(){
fastio;
cin >> N >> M;
for(int i=0; i<M; i++){
int u, v;
char w;
cin >> u >> v >> w;
if(u == v)
continue;
if(w == 'A'){
bus[u].pb(v);
bus[v].pb(u);
}else{
tr[u].pb(v);
tr[v].pb(u);
}
}
for(int i=1; i<=N; i++){
if(!group[i]){
cnt++;
DFS(i);
}
}
for(int i=1; i<=N; i++){
for(int j:bus[i]){
if(group[i] != group[j])
adj[group[i]].insert(group[j]);
}
}
for(int i=1; i<=N; i++){
if(adj[i].size()==cnt-1)
ans+=sz[i];
}
cout << ans << nl;
}
Compilation message (stderr)
menesinis_bilietas.cpp: In function 'int main()':
menesinis_bilietas.cpp:70:25: warning: comparison of integer expressions of different signedness: 'std::set<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
70 | if(adj[i].size()==cnt-1)
| ~~~~~~~~~~~~~^~~~~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |