比赛 2024暑期C班集训3 评测结果 WAWAWWWWWWWWWWWWWWWW
题目名称 Florr 最终得分 10
用户昵称 darkMoon 运行时间 0.228 s
代码语言 C++ 内存使用 3.82 MiB
提交时间 2024-07-03 08:56:03
显示代码纯文本
#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(), 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]] < 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;
            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";
}