結果

問題 No.468 役に立つ競技プログラミング実践編
ユーザー akusyounin2412akusyounin2412
提出日時 2019-03-25 19:39:26
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 3,104 bytes
コンパイル時間 1,476 ms
コンパイル使用メモリ 136,036 KB
実行使用メモリ 33,536 KB
最終ジャッジ日時 2024-04-17 10:47:51
合計ジャッジ時間 7,670 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 2 ms
5,376 KB
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
testcase_28 WA -
testcase_29 WA -
testcase_30 WA -
testcase_31 WA -
testcase_32 WA -
testcase_33 WA -
testcase_34 AC 112 ms
28,416 KB
testcase_35 AC 3 ms
5,376 KB
testcase_36 AC 2 ms
5,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

# include <iostream>
# include <algorithm>
#include <array>
# include <cassert>
#include <cctype>
#include <climits>
#include <numeric>
# include <vector>
# include <string>
# include <set>
# include <map>
# include <cmath>
# include <iomanip>
# include <functional>
# include <tuple>
# include <utility>
# include <stack>
# include <queue>
# include <list>
# include <bitset>
# include <complex>
# include <chrono>
# include <random>
# include <limits.h>
# include <unordered_map>
# include <unordered_set>
# include <deque>
# include <cstdio>
# include <cstring>
#include <stdio.h>
#include<time.h>
#include <stdlib.h>
#include <cstdint>
#include <cfenv>
#include<fstream>
//#include <bits/stdc++.h>
using namespace std;
using LL = long long;
using ULL = unsigned long long;
const long long MOD = 1000000000 + 7;//1000000000 + 7 998244353 924844033 1000000000 + 9;
constexpr long long INF = 1LL << 60;//numeric_limits<LL>::max();
const double PI = acos(-1);
#define fir first
#define sec second
#define thi third
#define debug(x) cerr<<#x<<": "<<x<<'\n'
typedef pair<LL, LL> Pll;
typedef pair<double, double> Dll;
typedef pair<LL, pair<LL, LL>> Ppll;
typedef pair<LL, pair<LL, bitset<100001>>> Pbll;
typedef pair<LL, pair<LL, vector<LL>>> Pvll;
typedef pair<LL, LL> Vec2;
struct Tll { LL first, second, third; };
struct Fll { LL first, second, third, fourth; };
typedef pair<LL, Tll> Ptll;
#define rep(i,rept) for(LL i=0;i<rept;i++)
#define Rrep(i,mf) for(LL i=mf-1;i>=0;i--)
void YN(bool f) {
	if (f)
		cout << "YES" << endl;
	else
		cout << "NO" << endl;
}
void yn(bool f) {
	if (f)
		cout << "Yes" << endl;
	else
		cout << "No" << endl;
}
struct Edge { LL to, cost; };
struct edge {
	LL from, to, cost;
};
vector<vector<Edge>>g,rev;
vector<edge>ed;
vector<Pll>pv;
set<LL>st;
map<Pll, LL>ma;
int di[4][2] = { { 0,1 },{ 1,0 },{ 0,-1 },{ -1,0 } };
string str, ss;
bool f[200000];
LL n, m, s, t, h, w, k, q, p, ans, sum, cnt,dp[200000];
vector<int> tsort(vector<vector<Edge>>g) {
	int n = g.size();
	enum { YET, VISITED, DONE };
	vector<int> res, flg(g.size(), YET);
	static const function<bool(int)> dfs = [&](int v) {
		flg[v] = VISITED;
		for (auto &e : g[v]) {
			int w = e.to;
			if (flg[w] != DONE && (flg[w] == VISITED || !dfs(w))) return false;
		}
		flg[v] = DONE;
		res.push_back(v);
		return true;
	};
	for (int i = 0; i < n; ++i)
		if (flg[i] == YET && !dfs(i)) return{};
	reverse(res.begin(), res.end());
	return res;
}
int main() {
	cin >> n >> m;
	g.resize(n);
	rev.resize(n);
	rep(i, m) {
		LL x, y, z;
		cin >> x >> y >> z;
		g[x].push_back(Edge{ y,z });
		rev[y].push_back(Edge{ x,z });
	}
	vector<int>v = tsort(g);
	rep(i, v.size()) {
		int cur = v[i];
		rep(j, g[cur].size()) {
			int nex = g[cur][j].to, cost = g[cur][j].cost;
			if (dp[nex] < dp[cur] + cost) {
				dp[nex] = dp[cur] + cost;
			}
		}
	}
	Rrep(i, v.size()) {
		int cur = v[i];
		rep(j, rev[cur].size()) {
			int nex = rev[cur][j].to, cost = rev[cur][j].cost;
			if (dp[nex]+ cost != dp[cur] ) {
				f[nex] = 1;
			}
		}
	}
	rep(i, n)if (f[i])cnt++;
	cout << dp[n - 1] << " " << cnt << "/" << n << endl;
	return 0;
}
0