#include <bits/stdc++.h>
using namespace std;
#define int long long
signed main()
{
int N, M, a, b, ans = 0;
cin >> N >> M;
char t;
bool is1 = true, is2 = true;
vector<vector<int>> adjlist(N, vector<int>());
for (int i = 0; i < M; i++)
{
cin >> a >> b >> t;
a--, b--;
adjlist[a].push_back(b);
adjlist[b].push_back(a);
if (t == 'A') is1 = false;
if (t == 'T') is2 = false;
}
queue<int> bfs;
set<int> visited;
bfs.push(1);
visited.insert(1);
while (!bfs.empty())
{
int i = bfs.front();
bfs.pop();
for (int j : adjlist[i])
if (visited.lower_bound(j) == visited.end() || *visited.lower_bound(j) != j)
visited.insert(j), bfs.push(j);
}
if (is1)
{
cout << ((int)visited.size() == N ? N : 0) << '\n';
return 0;
}
else if (is2)
{
for (int i = 0; i < N; i++)
{
if ((int)adjlist[i].size() >= N - 1)
ans++;
}
cout << ans << '\n';
return 0;
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1008 ms |
36340 KB |
Output is correct |
2 |
Correct |
0 ms |
344 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
4 ms |
11356 KB |
Output is correct |
5 |
Correct |
1 ms |
604 KB |
Output is correct |
6 |
Correct |
154 ms |
5356 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
11356 KB |
Output is correct |
2 |
Correct |
1 ms |
604 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
344 KB |
Output is correct |
5 |
Correct |
5 ms |
520 KB |
Output is correct |
6 |
Correct |
257 ms |
10472 KB |
Output is correct |
7 |
Correct |
573 ms |
48052 KB |
Output is correct |
8 |
Correct |
13 ms |
1976 KB |
Output is correct |
9 |
Correct |
24 ms |
2464 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
344 KB |
Output is correct |
5 |
Correct |
5 ms |
520 KB |
Output is correct |
6 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
7 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |