# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
362430 | _martynas | Monthly railway pass (LMIO18_menesinis_bilietas) | C++11 | 802 ms | 87620 KiB |
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;
using vi = vector<int>;
const int MAX_N = 5e5+5;
#define PB push_back
vi A[MAX_N];
vi T[MAX_N];
vector<vi> Groups;
int Group[MAX_N];
int group;
bool visited[MAX_N];
int n, m;
void dfs(int curr)
{
visited[curr] = true;
Group[curr] = group;
Groups[group].PB(curr);
for(int x : T[curr])
{
if(!visited[x])
{
dfs(x);
}
}
}
int main()
{
//freopen("lmio_2018_3e2_menesinis_bilietas_vyr.in", "r", stdin);
//freopen("lmio_2018_3e2_menesinis_bilietas_vyr.out", "w", stdout);
scanf("%d%d", &n, &m);
for(int i = 0; i < m; i++)
{
int a, b;
char c;
scanf("%d%d %c", &a, &b, &c);
a--;
b--;
if(c == 'A')
{
A[a].PB(b);
A[b].PB(a);
}
else
{
T[a].PB(b);
T[b].PB(a);
}
}
group = 0;
for(int i = 0; i < n; i++)
{
if(!visited[i])
{
Groups.PB(vi());
dfs(i);
group++;
}
}
int ans = 0;
set<int> OtherGroups;
for(vi &g : Groups)
{
for(int x : g)
{
for(int v : A[x])
{
if(Group[v] != Group[x])
OtherGroups.insert(Group[v]);
}
}
if(OtherGroups.size() == group - 1)
{
ans += g.size();
}
OtherGroups.clear();
}
printf("%d", ans);
return 0;
}
Compilation message (stderr)
# | 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... |