#include <bits/stdc++.h>
using namespace std;
vector <long long> adjlist[1000001];
bool visited [1000001];
void dfs(long long cur){
for(const long long&e:adjlist[cur]){
if(!visited[e]){
visited[e]=1;
dfs(e);
}
}
}
int main() {
long long n,e,a,b,s=0;
cin>>n>>e;
char mmmm;
for(long long i=0;i<e;i++){
cin>>a>>b>>mmmm;
adjlist[a].push_back(b);
adjlist[b].push_back(a);
}
for(long long i=0;i<n;i++){
if(!visited[i]){
dfs(i);
s++;
}
}
if (s == 1) cout << n;
else cout << 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
324 ms |
41808 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
12 ms |
23900 KB |
Output is correct |
2 |
Incorrect |
11 ms |
23900 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
11 ms |
23900 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
11 ms |
23900 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
324 ms |
41808 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |