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;
const int maxn = 1e5+3;
int i,j,p,q,n,m,k;
vector <int> v[maxn];
vector <int> rev[maxn];
int marked[maxn];
long long ans;
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
cin>>n>>m;
ans = m;
for(i=1;i<=m;i++)
{
cin>>p>>q;
v[p].push_back(q);
rev[q].push_back(p);
}
for(i=3;i<=n;i++)
{
if(rev[i].size()==i-1)
continue;
queue <pair<int,int>> qu;
marked[i] = i;
for(auto j:rev[i])
{
qu.push({j,0});
}
while(!qu.empty())
{
auto t = qu.front();
qu.pop();
//cout<<t.first<<" "<<t.second<<endl;
if(t.second>0)
{
ans++;
v[t.first].push_back(i);
rev[i].push_back(t.first);
}
for(auto j:v[t.first])
{
if(marked[j]!=i && j<i)
{
qu.push({j,t.second+1});
marked[j]=i;
}
}
}
}
cout<<ans<<endl;
return 0;
}
Compilation message (stderr)
Main.cpp: In function 'int main()':
Main.cpp:24:25: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
24 | if(rev[i].size()==i-1)
| ~~~~~~~~~~~~~^~~~~
# | 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... |