记录编号 589155 评测结果 AAAAAAAAAAAAAAAAAAAA
题目名称 Florr 最终得分 100
用户昵称 Gravatarliuyiche 是否通过 通过
代码语言 C++ 运行时间 0.220 s
提交时间 2024-07-03 16:33:55 内存使用 3.00 MiB
显示代码纯文本
        #include <bits/stdc++.h>
                        
        using namespace std;
             
        int n, m, k; 
        int c[100005];
        int vis[100005];
        bool vv[100005];
         
        struct node
        {
            int a, b;
        };
        vector<node> v(100005);
        vector<int> q;
         
        inline int solve(int x, int h)
        {
            if(x >= h)
                return 1e9;
            if(vv[vis[v[x].b]] != 0)
                return 1e9;
            vv[x] = 1;
            int ans = 1;
            if(vis[v[x].b] != 0)
                ans += solve(vis[v[x].b],h);
            vv[x] = 0;
            return ans;
        }
         
        inline void change(int x)
        {
            vv[x] = 1;
            if(vis[v[x].b] != 0)
                change(vis[v[x].b]);
            vis[v[x].a] = 0;
            vis[v[x].b] = x;
            swap(v[x].a,v[x].b);
            q.push_back(x);
            vv[x] = 0;
        }
         
        inline void dfs(int step, int cnt)
        {
            if(cnt == k)
                return;
            if(step == 0)
                return;
            if(c[v[step].a] < c[v[step].b])
            {
                int num = 1;
                if(vis[v[step].b] != 0)
                    num += solve(vis[v[step].b],step);
                if(num+cnt <= k)
                {
                    if(vis[v[step].b] != 0)
                        change(vis[v[step].b]);
                    vis[v[step].a] = 0;
                    vis[v[step].b] = step;
                    swap(v[step].a,v[step].b);
                    q.push_back(step);
                    dfs(step-1,cnt+num);
                }
                else dfs(step-1,cnt);
            }
            else dfs(step-1,cnt);
            
        }
                
        int main()
        {
            freopen("Florr.in", "r", stdin);
            freopen("Florr.out", "w", stdout);
                    
            ios::sync_with_stdio(false);
            cin.tie(0); cout.tie(0);
                        
            cin >> n >> m >> k;
            for(int i = 1; i <= n; ++i)
                cin >> c[i];
            for(int i = 1; i <= m; ++i)
            {
                cin >> v[i].a >> v[i].b;
                vis[v[i].a] = i;
            }
            
            dfs(m,0);
            
            int len = q.size();
            cout << len << '\n';
            for(int i = 0; i < len; ++i)
                cout << q[i] << '\n';
                
           	return 0;
        }