记录编号 589133 评测结果 AAAAAAAAAAAAAAAAAAAA
题目名称 Florr 最终得分 100
用户昵称 Gravatarwdsjl 是否通过 通过
代码语言 C++ 运行时间 0.261 s
提交时间 2024-07-03 15:39:40 内存使用 3.82 MiB
显示代码纯文本
#include<bits/stdc++.h>
#define int long long
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(),n_i , a[N], b[N], belong[N], c[N], e[N];
vector<int> v;
int dfs(int i, stack<int> &s){
    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]] < n_i){
        int ans = dfs(belong[b[i]], s);
        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;
            n_i=i;
            if(dfs(i, s)){
                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";
}