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;
#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)bfs.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 |
---|
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... |