QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#153785#7041. Girls Band PartyPetroTarnavskyi#RE 0ms0kbC++172.0kb2023-08-30 23:16:342023-08-30 23:16:34

Judging History

你现在查看的是最新测评结果

  • [2023-08-30 23:16:34]
  • 评测
  • 测评结果:RE
  • 用时:0ms
  • 内存:0kb
  • [2023-08-30 23:16:34]
  • 提交

answer

#include <bits/stdc++.h>

using namespace std;

#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define RFOR(i, a, b) for (int i = (a) - 1; i >= (b); i--)
#define FILL(a, b) memset(a, b, sizeof(a))
#define SZ(a) int(a.size())
#define ALL(a) a.begin(), a.end()
#define PB push_back
#define MP make_pair

typedef long long LL;
typedef vector<int> VI;
typedef pair<int, int> PII;
typedef double db;

const int N = 1 << 17;
const int M = 1 << 18;

const LL LINF = 1.1e18;

vector<PII> g[N];
int used[N];
PII par[N];
int tin[N], fup[N], timer;
LL depth[N];
vector<PII> cycles[N];
set<pair<int, int>> bridges;
LL dp[N][2];

void dfs(int v, int p)
{
	used[v] = 1;
	tin[v] = fup[v] = timer++;
	for (auto [to, w] : g[v])
	{
		if (to == p)
			continue;
		if (used[to] == 0)
		{
			par[to] = {v, w};
			depth[to] = depth[v] + w;
			dfs(to, v);
			fup[v] = min(fup[v], fup[to]);
			if (fup[to] == tin[to]) 
				bridges.emplace(v, to);
		}
		else if (used[to] == 1)
		{
			cycles[to].emplace_back(v, w);
		}
	}
	vector<LL> vec0, vec1;
	for (auto [to, w] : g[v])
	{
		if (bridges.count(MP(v, to)))
		{
			vec0.push_back(dp[to][0] + 2 * w);
			vec1.push_back(dp[to][1] + w);
		}
	}
	for (auto [to, w] : cycles[v])
	{
		LL lenCycle = depth[to] - depth[v] + w;
		LL s0 = 0;
		for (int u = to; u != v; u = par[u].first)
		{
			s0 += dp[u][0];
		}
		LL val1 = LINF;
		for (int u = to; u != v; u = par[u].first)
		{
			LL d = depth[u] - depth[v];
			d = min(d, lenCycle - d);
			val1 = min(val1, s0 + lenCycle - dp[u][0] + dp[u][1] + d);
		}
		vec0.push_back(s0 + lenCycle);
		vec1.push_back(val1);
	}
	dp[v][0] = accumulate(ALL(vec0), 0LL);
	dp[v][1] = LINF;
	FOR(i, 0, SZ(vec0))
		dp[v][1] = min(dp[v][1], dp[v][0] - vec0[i] + vec1[i]);
	used[v] = 2;
}

int main()
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	int n, m;
	cin >> n >> m;
	FOR(i, 0, m)
	{
		int u, v, w;
		cin >> u >> v >> w;
		u--;
		v--;
		g[u].emplace_back(v, w);
		g[v].emplace_back(u, w);
	}
	dfs(0, -1);
	cout << dp[0][1] << "\n";
}

詳細信息

Test #1:

score: 0
Runtime Error

input:

1
6
Saaya Power 45000
Kokoro Happy 45000
Kasumi Cool 45000
Rimi Power 45000
Aya Pure 45000
Aya Power 2000
Saaya Tae Kasumi Rimi Arisa
Power

output:


result: