蒟蒻求助!!!

CPP 刷题王 2024-03-28 21:44:17 2024-03-28 21:45:50 26

题目传送门

代码仅欲通过特殊性质

蒟蒻仅AC样例1,其余WA、TLE与MLE

#include <bits/stdc++.h>
using namespace std;
#define int long long
const int N = 4e5 + 10;
struct node {
	int a, len;
//	operator < (const int &aa, const int &bb) {
//		return aa.len > bb.len;
//	}
};
vector<int> v[N];
int n, m, len2;
queue<node> q;
void bfs(int startk) {
	q.push({startk, 0});
	while (!q.empty()) {
		node t = q.front();
		q.pop();
		int u = t.a, len = v[u].size();
		for (int i = 0; i < len; i++) {
			len2 = max(len2, t.len + 1);
			q.push({v[u][i], t.len + 1});
		}
	}
}
signed main() {
	ios::sync_with_stdio(false);
	ios_base::sync_with_stdio(false);
	cin.tie(0), cout.tie(0);
	cin >> n >> m;
	int a, b, l;
	for (int i = 1; i <= m; i++) {
		cin >> a >> b >> l;
		v[a].push_back(b);
	}
	for (int i = 1; i <= n; i++) {
		bfs(i);
		cout << len2 << ' ' << len2 * l << endl;
		len2 = 0;
	}
	return 0;
}
/*
4 5
4 3 10
4 2 10
3 1 10
2 1 10
4 1 10

4 5
4 3 4
4 2 2
3 1 5
2 1 10
4 1 1
*/
{{ vote && vote.total.up }}

共 5 条回复

root 站长

@CPP 我看到了,再找 bug 。

CPP 刷题王

@--- 我只是想知道我的代码怎么改对第一个子任务。。。正解我知道

---

@CPP 你是谁

CPP 刷题王

@root 求助!!!