Compare commits

..

No commits in common. "66f957900fa8e0c8bad82265f37fbad4c838dad2" and "37ca18855adc2503452fc5ce6471667d7d519985" have entirely different histories.

3 changed files with 59 additions and 182 deletions

59
src/8/15/P8817.cpp Normal file
View File

@ -0,0 +1,59 @@
#include <cstdint>
#include <functional>
#include <iostream>
#include <queue>
#include <utility>
#include <vector>
using ll = int64_t;
ll n,m,k;
std::vector<ll> score;
std::vector<std::vector<ll>> edg;
std::vector<std::vector<bool>> cango;
std::vector<std::vector<ll>> best3;
void dfscango(ll from,ll cur, ll curk){
if(curk>k){
return;
}
for(ll i=0;i<edg[cur].size();i++){
cango[from][edg[cur][i]]=true;
dfscango(from, edg[cur][i], curk+1);
}
return;
}
int main(){
std::cin>>n>>m>>k;
score.resize(n+1);
edg.resize(n+1);
cango.resize(n+1,std::vector<bool>(n+1));
best3.resize(n+1);
for(ll i=2;i<=n;i++){
std::cin>>score[i];
}
for(ll i=1;i<=m;i++){
ll u,v;
std::cin>>u>>v;
edg[u].push_back(v);
edg[v].push_back(u);
}
for(ll i=1;i<=n;i++){
dfscango(i, i, 0);
}
for(ll i=2;i<=n;i++){
std::priority_queue<std::pair<ll, ll>,std::vector<std::pair<ll, ll>>,std::greater<>> pr;
for(ll j=2;j<=n;j++){
if(i==j)continue;
if(cango[i][j]&&cango[j][1]){
pr.emplace(score[j],j);
}
}
//TODO
}
for(ll B=2;B<=n;B++){
for(ll C=B+1;C<=n;C++){
}
}
}

View File

@ -1,83 +0,0 @@
#include <algorithm>
#include <cstdint>
#include <iostream>
#include <vector>
using ll = int64_t;
const int MAXN = 500 + 5;
const int MAXK = 100 + 5;
int n;
int k;
struct P {
ll x, y;
bool operator<(const P &other) const {
if (x != other.x)
return x < other.x;
return y < other.y;
}
} p[MAXN];
int dp[MAXN][MAXK];
int main() {
std::ios_base::sync_with_stdio(false);
std::cin.tie(nullptr);
std::cin >> n >> k;
for (int i = 1; i <= n; i++) {
std::cin >> p[i].x >> p[i].y;
}
std::sort(p + 1, p + n + 1);
ll maxlen = 0;
for (int i = 1; i <= n; i++) {
dp[i][0] = 1;
for (int j = 1; j < i; j++) {
if (p[j].y <= p[i].y) {
ll dist = (p[i].x - p[j].x) + (p[i].y - p[j].y);
if (dist <= 0)
continue;
ll cost = dist - 1;
for (int pk = 0; pk <= k; pk++) {
if (dp[j][pk] > 0) {
ll tot = pk + cost;
if (tot <= k) {
int nlen = dp[j][pk] + dist;
dp[i][tot] = std::max(dp[i][tot], nlen);
}
}
}
}
}
}
maxlen = k + 1;
for (int i = 1; i <= n; i++) {
for (int j = 0; j <= k; j++) {
if (dp[i][j] > 0) {
maxlen = std::max(maxlen, (ll)dp[i][j] + (k - j));
}
}
}
std::cout << maxlen << "\n";
return 0;
}

View File

@ -1,99 +0,0 @@
#include <algorithm>
#include <iostream>
#include <queue>
#include <vector>
using ll = long long;
const int MAXN = 2505;
int n;
int m;
int k;
ll sc[MAXN];
std::vector<int> adj[MAXN];
int dist[MAXN][MAXN];
std::vector<int> pre[MAXN];
void bfs(int s) {
std::queue<std::pair<int, int>> q;
q.push({s, 0});
dist[s][s] = 0;
while (!q.empty()) {
auto [u, d] = q.front();
q.pop();
if (d > k) {
continue;
}
for (int v : adj[u]) {
if (dist[s][v] == -1) {
dist[s][v] = d + 1;
q.push({v, d + 1});
}
}
}
}
int main() {
std::ios_base::sync_with_stdio(false);
std::cin.tie(nullptr);
std::cin >> n >> m >> k;
for (int i = 2; i <= n; ++i) {
std::cin >> sc[i];
}
for (int i = 0; i < m; ++i) {
int u, v;
std::cin >> u >> v;
adj[u].push_back(v);
adj[v].push_back(u);
}
for (int i = 1; i <= n; ++i) {
for (int j = 1; j <= n; ++j) {
dist[i][j] = -1;
}
}
for (int i = 1; i <= n; ++i) {
bfs(i);
}
for (int i = 2; i <= n; ++i) {
for (int j = 2; j <= n; ++j) {
if (i == j)
continue;
if (dist[1][j] != -1 && dist[j][i] != -1) {
pre[i].push_back(j);
}
}
std::sort(pre[i].begin(), pre[i].end(), [&](int a, int b) { return sc[a] > sc[b]; });
if (pre[i].size() > 3) {
pre[i].resize(3);
}
}
ll ans = 0;
for (int b = 2; b <= n; ++b) {
for (int c = 2; c <= n; ++c) {
if (b == c)
continue;
if (dist[b][c] != -1) {
for (int a : pre[b]) {
for (int d : pre[c]) {
if (a != c && a != d && b != d) {
ans = std::max(ans, sc[a] + sc[b] + sc[c] + sc[d]);
}
}
}
}
}
}
std::cout << ans << std::endl;
}