Submission #662030
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; while(true) { Node *donenode = nullptr; REP(i, n) { if(nodes[i].done || nodes[i].cost < 0) { continue; } if(donenode == nullptr || nodes[i].cost < donenode->cost) { donenode = &nodes[i]; } } // finish check if(donenode == nullptr) break; donenode->done = true; REP(i, donenode->edges_to.size()) { int to = donenode->edges_to[i]; int cost = donenode->cost + donenode->edges_cost[i]; if(nodes[to].cost < 0 || cost < nodes[to].cost) { nodes[to].cost = cost; } } } 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 | 2905 Byte |
Status | AC |
Exec Time | 229 ms |
Memory | 2144 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 | 28 ms | 924 KB |
sample_02.txt | AC | 25 ms | 916 KB |
sample_03.txt | AC | 27 ms | 860 KB |
test_01.txt | AC | 28 ms | 912 KB |
test_02.txt | AC | 138 ms | 916 KB |
test_03.txt | AC | 229 ms | 2144 KB |
test_04.txt | AC | 67 ms | 916 KB |
test_05.txt | AC | 89 ms | 1324 KB |
test_06.txt | AC | 32 ms | 988 KB |
test_07.txt | AC | 176 ms | 2016 KB |
test_08.txt | AC | 27 ms | 868 KB |
test_09.txt | AC | 70 ms | 1252 KB |
test_10.txt | AC | 32 ms | 996 KB |
test_11.txt | AC | 33 ms | 984 KB |
test_12.txt | AC | 86 ms | 1048 KB |
test_13.txt | AC | 33 ms | 1048 KB |
test_14.txt | AC | 36 ms | 1004 KB |
test_15.txt | AC | 161 ms | 2020 KB |
test_16.txt | AC | 36 ms | 996 KB |
test_17.txt | AC | 75 ms | 1256 KB |
test_18.txt | AC | 82 ms | 1048 KB |
test_19.txt | AC | 39 ms | 992 KB |
test_20.txt | AC | 37 ms | 960 KB |
test_21.txt | AC | 26 ms | 920 KB |
test_22.txt | AC | 49 ms | 1000 KB |
test_23.txt | AC | 27 ms | 892 KB |
test_24.txt | AC | 162 ms | 976 KB |
test_25.txt | AC | 163 ms | 920 KB |
test_26.txt | AC | 56 ms | 872 KB |
test_27.txt | AC | 66 ms | 860 KB |
test_28.txt | AC | 161 ms | 924 KB |
test_29.txt | AC | 161 ms | 920 KB |
test_30.txt | AC | 31 ms | 920 KB |
test_31.txt | AC | 28 ms | 916 KB |
test_32.txt | AC | 161 ms | 916 KB |
test_33.txt | AC | 162 ms | 916 KB |
test_34.txt | AC | 28 ms | 920 KB |
test_35.txt | AC | 48 ms | 920 KB |
test_36.txt | AC | 162 ms | 868 KB |