/* * James Bond (via mjd@cs.auckland.ac.nz) */ #include #include #include #include #include using namespace std; typedef vector NLIST; // node (neighbor) list typedef vector< NLIST > ADJLIST; // graph data structure const static int MAXNODES=100; const static int LLEN=1024; const static int BIGINT=0xFFFFFFF; static int N, M, S, T; // global game parameters class Game { public: ADJLIST adj; NLIST bomb; int adjCost[MAXNODES][MAXNODES]; // creators + destroyers // Game(int n = 0 ) : adj(n), bomb(n) { } ~Game() {} // stream I/0 // friend ostream& operator<<(ostream&, const Game&); friend istream& operator>>(istream&, Game&); int order() const // number of vertices { return adj.size(); } int edgeCost(int u, int v) const { int n = order(); assert(u >= 1 && u <= n); assert(v >= 1 && v <= n); assert(u != v); assert(adjCost[u-1][v-1]==adjCost[v-1][u-1]); return adjCost[u-1][v-1]; } bool addEdge(int u, int v, int t) // false if already exists { if ( edgeCost(u, v) > 0 ) { assert(false); return false; } adj[u-1].push_back(v-1); adj[v-1].push_back(u-1); adjCost[u-1][v-1] = adjCost[v-1][u-1] = t; return true; } int degree(int u) const { return adj[u-1].size(); } }; ostream& operator<<(ostream& o, const Game& G) { int n=G.order(); o << n << "\n"; for (int i=0; i>(istream& in, Game& G) { char line[LLEN]; in.getline(line, LLEN); istringstream lineIn(line); lineIn >> N >> M >> S >> T; G.adj.resize(N); G.bomb.resize(N); // get nodes for (int i=0; i> b; G.bomb[i] = (b==0 ? BIGINT : b); G.adj[i].resize(0); for (int j=0; j> v1 >> v2 >> t; G.addEdge(v1,v2,t); } return in; } int main() { Game G; while (true) { cin >> G; int n = G.order(); if (n==0) break; #ifdef DEBUG cerr << G; #endif NLIST reach(n); for (int i=0; i