# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
920965 | WongYiKai | Monthly railway pass (LMIO18_menesinis_bilietas) | C++14 | 314 ms | 83384 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;
typedef long long ll;
ll visited[600000];
ll type[600000];
ll c=1;
ll sets[600000];
vector<ll> adj[600000],adj2[600000];
void dfs(ll vertex){
visited[vertex] = 1;
type[vertex] = c;
sets[c]++;
for (auto item:adj[vertex]){
if (visited[item]==0){
dfs(item);
}
}
}
int main(){
ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
ll n,m;
cin >> n >> m;
for (int i=0;i<m;i++){
ll a,b;
char t;
cin >> a >> b >> t;
if (t=='T'){
adj[a].push_back(b);
adj[b].push_back(a);
}
else {
adj2[a].push_back(b);
adj2[b].push_back(a);
}
}
for (int i=1;i<=n;i++){
if (visited[i]==0){
dfs(i);
c++;
}
}
vector<ll> con[c+5];
for (int i=1;i<=n;i++){
for (auto item:adj2[i]){
if (type[i]!=type[item]){
con[type[i]].push_back(type[item]);
}
}
}
c--;
ll total=0;
for (int i=1;i<=c;i++){
//cout << con[i].size() << "\n";
if (con[i].size() == c-1) total += sets[i];
}
cout << total;
}
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... |