比赛 |
2024暑期C班集训3 |
评测结果 |
ATAATATTAAATAAAAAATT |
题目名称 |
Florr |
最终得分 |
65 |
用户昵称 |
liuyiche |
运行时间 |
7.168 s |
代码语言 |
C++ |
内存使用 |
4.82 MiB |
提交时间 |
2024-07-03 09:40:23 |
显示代码纯文本
#include <bits/stdc++.h>
using namespace std;
int n, m, k;
int c[100005];
int vis[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(vis[v[x].b] != 0)
return solve(vis[v[x].b],h)+1;
else
return 1;
}
inline void change(int x)
{
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);
}
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);
cout << q.size() << '\n';
for(int i = 0; i < q.size(); ++i)
cout << q[i] << '\n';
return 0;
}