记录编号 386423 评测结果 AAAAAAAAAAAAAAAAAAAA
题目名称 月考统计 最终得分 100
用户昵称 Gravatarsxysxy 是否通过 通过
代码语言 C++ 运行时间 0.646 s
提交时间 2017-03-24 15:31:05 内存使用 0.33 MiB
显示代码纯文本
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cstdarg>
#include <list>
#include <queue>
#include <vector>
using namespace std;
#define MAXN 1003
vector<int> G[MAXN];
bool vis[MAXN];
int dist[MAXN], cnt[MAXN];
struct edge{
	int from, to, value;
}; vector<edge> edges;
inline void addedge(int u, int v, int c){
	edges.push_back((edge){
		u, v, c
	});
	int k = edges.size();
	G[u].push_back(k-1);
}
int main(){
	freopen("ExamStat.in", "r", stdin);
	freopen("ExamStat.out", "w", stdout);
	int n, m; scanf("%d %d", &n, &m);
	while(m--){
		int u, v, c; scanf("%d %d %d", &u, &v, &c);
		addedge(u, v, -c);
	}
	queue<int> q;
	for(int i = 1; i <= n; i++){
		q.push(i);
		vis[i] = true; cnt[i] = 1;
	}
	while(!q.empty()){
		int u = q.front(); q.pop();
		vis[u] = false;
		for(vector<int>::iterator it = G[u].begin(); it != G[u].end(); ++it){
			edge &e = edges[*it];
			if(dist[u] + e.value> dist[e.to]){
				dist[e.to] = dist[u]+e.value;
				if(!vis[e.to]){
					if(cnt[e.to] == n){
						puts("SOMEONE LAY!");
						return 0;
					}
					q.push(e.to);
					vis[e.to] = true;
					cnt[e.to]++;	
				}
			}
		}
	}
	for(int i = 1; i <= n; i++)
		printf(i==n?"%d\n":"%d ", dist[i]);
	return 0;
}