记录编号 |
589115 |
评测结果 |
AAAAAAAAAAAAAAAAAAAA |
题目名称 |
Florr |
最终得分 |
100 |
用户昵称 |
darkMoon |
是否通过 |
通过 |
代码语言 |
C++ |
运行时间 |
0.866 s |
提交时间 |
2024-07-03 14:38:12 |
内存使用 |
4.76 MiB |
显示代码纯文本
#include<bits/stdc++.h>
#define int long long
#define fin cin
#define fout cout
using namespace std;
//ifstream fin("Florr.in");
//ofstream fout("Florr.out");
auto mread = [](){
int x;
fin >> x;
return x;
};
const int N = 1e5 + 5;
int n = mread(), m = mread(), k = mread(), a[N], b[N], belong[N], c[N], e[N];
vector<int> v;
int dfs(int i, stack<int> &s, int root){
e[i] = 1;
s.push(i);
if(belong[b[i]] == 0){
e[i] = 0;
return 1;
}
else if(e[belong[b[i]]] == 0 && belong[b[i]] < root){
int ans = dfs(belong[b[i]], s, root);
e[i] = 0;
return ans;
}
else{
e[i] = 0;
return 0;
}
}
signed main(){
for(int i = 1; i <= n; i ++)
c[i] = mread();
for(int i = 1; i <= m; i ++){
a[i] = mread(), b[i] = mread();
belong[a[i]] = i;
}
for(int i = m; i >= 1; i --){
if(c[a[i]] < c[b[i]]){
stack<int> s;
if(dfs(i, s, i)){
if(s.size() <= k)
while(s.size()){
int x = s.top();
belong[a[x]] = 0;
belong[b[x]] = x;
swap(a[x], b[x]);
v.push_back(x);
s.pop();
k --;
}
}
}
}
fout << v.size() << "\n";
for(int x : v)
fout << x << "\n";
}