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>
using namespace std;
typedef long long ll;
const ll mx=5e6+10;
const int mod= 1e9+7 ;
const ll inf=1e18;
//***while there is life there is hope
//int a[mx];
int n,m;
vector<pair<int,int>>adj[mx];
int vis[mx];
void dfs(int i,int par){
vis[i]=1;
for(auto it:adj[i]){
if(it.first==par||vis[it.first]){continue;}
dfs(it.first,i);
}
return;
}
int ist(char x){
return (x=='A');
}
int main() {
cin>>n>>m;
for(int i=0;i<m;i++){
int x,y;char t;
cin>>x>>y>>t;
adj[x].push_back({y,ist(t)});
adj[y].push_back({x,ist(t)});
}
dfs(1,-1);
int ok;
for(int i=1;i<=n;i++){
if(vis[i]==0){ok=0;}
}
if(ok){
cout<<n;
}else{
cout<<0;
}
}
# | 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... |