题解:P18049 [UKIEPC 2023] Kernel Scheduler
YuLuCangLing · · 题解
简要题意:给定
由于没有自环,所以在满足
在一张有向图中,若所有边均满足
令图上有两点
令从点
所以
所以,该图中没有环。
考虑建反图,则该结论对于所有边均满足
所以,我们只需要选所有满足
#include<bits/stdc++.h>
using namespace std;
int n,m;
vector<int> ans1,ans2,tempans;
int main()
{
cin>>n>>m;
for(int i=1,a,b; i<=m; i++) {
cin>>a>>b;
if(a<b) ans1.push_back(i);else ans2.push_back(i);
}
if(ans1.size()>=ans2.size()) tempans=ans1;else tempans=ans2;
cout<<"YES\n"<<tempans.size()<<'\n';
for(int i=0; i<tempans.size(); i++) cout<<tempans[i]<<' ';
return 0;
}