Submission #662009


Source Code Expand

#include <iostream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <queue>

#include <map>
#include <set>
#include <string>
#include <algorithm>
#include <functional>
using namespace std;
#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define RFOR(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define REP(i,n) for (int i=0;i<(n);i++)
#define RREP(i,n) for (int i=(n)-1;i>=0;i--)
#define INF 1<<29
#define ALEN(ARR) (sizeof(ARR) / sizeof((ARR)[0]))
#define MP make_pair
#define mp make_pair
#define pb push_back
#define PB push_back
#define DEBUG(x) cout<<#x<<": "<<x<<endl
#define DDEBUG(x,y) cout<<#x<<": "<<x<<", "<<#y<<": "<<y<<endl
#define ll long long
#define ull unsigned long long
#define MOD 1000000007

struct Node {
    // このノードから伸びるエッジの情報
    vector<int> edges_to;    // 各エッジの接続先のノード番号
    vector<int> edges_cost;  // 各エッジのコスト

    // ダイクストラ法のためのデータ
    bool done;  // 確定ノードか否か
    int cost;   // このノードへの現時点で判明している最小コスト

	bool operator> (const Node  &) const;
	bool operator< (const Node  &) const;
};

bool Node::operator> (const Node  &n) const {return cost >  n.cost;}
bool Node::operator< (const Node  &n) const {return cost <  n.cost;}

typedef priority_queue <Node, vector<Node>, greater<Node> > dijk_p_que;

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	cout.precision(16);

	int n, m;
	cin >> n >> m;

	vector<Node> nodes(n);
	// init
	REP(i, n) {
		nodes[i].done = false;
		nodes[i].cost = -1;
	}

	// connect
	REP(i, m) {
		int from, to, cost;
		cin >> from >> to >> cost;
		from--; to--;
		nodes[from].edges_to.pb(to);
		nodes[from].edges_cost.pb(cost);
		nodes[to].edges_to.pb(from);
		nodes[to].edges_cost.pb(cost);
	}

	nodes[0].cost = 0;
	int res = INF;
	REP(s, n) {
		nodes[s].cost = 0;
		dijk_p_que p_que;
		p_que.push(nodes[s]);

		while(!p_que.empty()) {
			Node donenode = p_que.top();
			p_que.pop();
			// DDEBUG(s, donenode.edges_to.size());
			if(donenode.done) continue;

			// 確定フラグを立てる
			donenode.done = true;
			REP(i, donenode.edges_to.size()) {
				int to = donenode.edges_to[i];
				int cost = donenode.edges_cost[i] + donenode.cost;
				if(nodes[to].cost < 0 || cost < nodes[to].cost) {
					nodes[to].cost = cost;
					if(!nodes[to].done) p_que.push(nodes[to]);
				}
			}
		}

		int maxcost = 0;
		REP(i, n) {
			if(nodes[i].cost > 0) maxcost = max(maxcost, nodes[i].cost);
			// DDEBUG(i, nodes[i].cost);
			// reset node
			nodes[i].cost = -1;
			nodes[i].done = false;
		}
		res = min(res, maxcost);
	}

	// cout << "** RESULT **" << endl; // debug
	cout << res << endl;
}

Submission Info

Submission Time
Task D - バスと避けられない運命
User yumechi
Language C++ (G++ 4.6.4)
Score 0
Code Size 2829 Byte
Status TLE
Exec Time 5036 ms
Memory 7296 KB

Judge Result

Set Name All
Score / Max Score 0 / 100
Status
AC × 33
TLE × 3
Set Name Test Cases
All test_01.txt, test_02.txt, test_03.txt, test_04.txt, test_05.txt, test_06.txt, test_07.txt, test_08.txt, test_09.txt, test_10.txt, test_11.txt, test_12.txt, test_13.txt, test_14.txt, test_15.txt, test_16.txt, test_17.txt, test_18.txt, test_19.txt, test_20.txt, test_21.txt, test_22.txt, test_23.txt, test_24.txt, test_25.txt, test_26.txt, test_27.txt, test_28.txt, test_29.txt, test_30.txt, test_31.txt, test_32.txt, test_33.txt, test_34.txt, test_35.txt, test_36.txt
Case Name Status Exec Time Memory
sample_01.txt AC 27 ms 880 KB
sample_02.txt AC 25 ms 968 KB
sample_03.txt AC 24 ms 1044 KB
test_01.txt AC 27 ms 1048 KB
test_02.txt AC 198 ms 984 KB
test_03.txt TLE 5035 ms 7296 KB
test_04.txt AC 363 ms 1176 KB
test_05.txt AC 1815 ms 3112 KB
test_06.txt AC 177 ms 1480 KB
test_07.txt TLE 5036 ms 6632 KB
test_08.txt AC 30 ms 948 KB
test_09.txt AC 1368 ms 2860 KB
test_10.txt AC 136 ms 1448 KB
test_11.txt AC 166 ms 1472 KB
test_12.txt AC 1087 ms 1580 KB
test_13.txt AC 178 ms 1476 KB
test_14.txt AC 265 ms 1568 KB
test_15.txt TLE 5035 ms 6476 KB
test_16.txt AC 292 ms 1588 KB
test_17.txt AC 1468 ms 2940 KB
test_18.txt AC 1048 ms 1596 KB
test_19.txt AC 312 ms 1608 KB
test_20.txt AC 316 ms 1556 KB
test_21.txt AC 26 ms 1048 KB
test_22.txt AC 508 ms 1392 KB
test_23.txt AC 28 ms 1052 KB
test_24.txt AC 138 ms 1064 KB
test_25.txt AC 139 ms 1044 KB
test_26.txt AC 67 ms 1044 KB
test_27.txt AC 75 ms 948 KB
test_28.txt AC 143 ms 1048 KB
test_29.txt AC 143 ms 1052 KB
test_30.txt AC 37 ms 1044 KB
test_31.txt AC 28 ms 1044 KB
test_32.txt AC 137 ms 1048 KB
test_33.txt AC 134 ms 948 KB
test_34.txt AC 32 ms 1048 KB
test_35.txt AC 60 ms 1044 KB
test_36.txt AC 139 ms 976 KB