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;
vector< pair < char,pair < int,int > > > edges;
vector<int>g[500001],g2[500001];
int vst[500001];
void dfs(int node,int p,int col)
{
vst[node]=col;
for(int go:g[node])
if(go!=p && vst[go]==0)
dfs(go,node,col);
}
bool selected[500001];
int main()
{
int v,e,comp=0;
cin>>v>>e;
while(e--)
{
char c;
int a,b;
cin>>a>>b>>c;
edges.push_back({c,{a,b}});
}
//sort(edges.begin(),edges.end());
for(int i=edges.size()-1;i>=0;i--)
{
if(edges[i].first=='T')
{
g[edges[i].second.first].push_back(edges[i].second.second);
g[edges[i].second.second].push_back(edges[i].second.first);
}
}
for(int i=1;i<=v;i++)
{
if(vst[i]==0)dfs(i,0,comp+1),
comp++;
}
//cout<<"comp: "<<comp<<endl;
//for(int i=1;i<=v;i++)cout<<visit[i]<<" ";cout<<endl;
int cav=0;
/*
for(int i=1;i<=v;i++)
for(int n:g[i])
if(visit[i]!=visit[n])g2[i].push_back(n),g2[n].push_back(i);
*/
for(int i=0;i<edges.size();i++)
if(edges[i].first=='A')
g2[vst[edges[i].second.first]].push_back(vst[edges[i].second.second]),g2[vst[edges[i].second.second]].push_back(vst[edges[i].second.first]);
for(int i=1;i<=v;i++)
{
int ini=comp-1;
for(int go:g2[vst[i]])
{
if(vst[i]!=go && selected[go]==0)
{
ini--;
selected[go]=1;
}
}
//cout<<"i: "<<i<<" ini: "<<ini<<endl;
if(ini==0)cav++;
for(int go:g2[vst[i]])
selected[go]=0;
}
cout<<cav;
return 0;
}
Compilation message (stderr)
menesinis_bilietas.cpp: In function 'int main()':
menesinis_bilietas.cpp:47:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<char, std::pair<int, int> > >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
47 | for(int i=0;i<edges.size();i++)
| ~^~~~~~~~~~~~~
# | 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... |