Submission #662013
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 // refer: // http://www.deqnotes.net/acmicpc/dijkstra/ 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++11 (GCC 4.8.1) |
Score | 100 |
Code Size | 2888 Byte |
Status | AC |
Exec Time | 2735 ms |
Memory | 5724 KB |
Judge Result
Set Name | All | ||
---|---|---|---|
Score / Max Score | 100 / 100 | ||
Status |
|
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 | 31 ms | 1048 KB |
sample_02.txt | AC | 26 ms | 1044 KB |
sample_03.txt | AC | 25 ms | 952 KB |
test_01.txt | AC | 26 ms | 1044 KB |
test_02.txt | AC | 71 ms | 1044 KB |
test_03.txt | AC | 2735 ms | 5724 KB |
test_04.txt | AC | 110 ms | 1180 KB |
test_05.txt | AC | 780 ms | 2804 KB |
test_06.txt | AC | 75 ms | 1324 KB |
test_07.txt | AC | 1954 ms | 4860 KB |
test_08.txt | AC | 28 ms | 1048 KB |
test_09.txt | AC | 524 ms | 2428 KB |
test_10.txt | AC | 61 ms | 1364 KB |
test_11.txt | AC | 70 ms | 1304 KB |
test_12.txt | AC | 295 ms | 1432 KB |
test_13.txt | AC | 78 ms | 1328 KB |
test_14.txt | AC | 119 ms | 1436 KB |
test_15.txt | AC | 1856 ms | 4676 KB |
test_16.txt | AC | 135 ms | 1468 KB |
test_17.txt | AC | 632 ms | 2544 KB |
test_18.txt | AC | 284 ms | 1408 KB |
test_19.txt | AC | 143 ms | 1516 KB |
test_20.txt | AC | 119 ms | 1424 KB |
test_21.txt | AC | 26 ms | 1048 KB |
test_22.txt | AC | 157 ms | 1428 KB |
test_23.txt | AC | 27 ms | 1004 KB |
test_24.txt | AC | 56 ms | 948 KB |
test_25.txt | AC | 60 ms | 1044 KB |
test_26.txt | AC | 36 ms | 948 KB |
test_27.txt | AC | 41 ms | 948 KB |
test_28.txt | AC | 57 ms | 1044 KB |
test_29.txt | AC | 61 ms | 944 KB |
test_30.txt | AC | 31 ms | 1084 KB |
test_31.txt | AC | 27 ms | 948 KB |
test_32.txt | AC | 58 ms | 1000 KB |
test_33.txt | AC | 61 ms | 944 KB |
test_34.txt | AC | 28 ms | 876 KB |
test_35.txt | AC | 37 ms | 948 KB |
test_36.txt | AC | 56 ms | 1000 KB |