/* >>~~ UVa Online Judge ACM Problem Solution ~~<< ID: 10048 Name: Audiophobia Problem: https://onlinejudge.org/external/100/10048.pdf Language: C++ Author: Arash Shakery Email: arash.shakery@gmail.com */ #include #include #include #include #include using namespace std; #define MAXN 1001 int ids[MAXN]; int find(int i) { if (ids[i] == i) return i; return ids[i] = find(ids[i]); } void join(int x, int y) { ids[find(x)] = find(y); } struct Edge { int x, y, d; bool operator < (const Edge &e) const { return d adj[MAXN]; int mp[MAXN][MAXN]; int seen[MAXN]; int dfs(int v, int w) { if (v==w) return 0; if (seen[v]) return -1; seen[v] = 1; int mx = -1; for (int i: adj[v]) { int r = dfs(i, w); if (r>=0) mx = max(mx, max(r, mp[v][i])); } seen[v] = 0; return mx; } int main(){ int c,s,q, cse=1, x, y; while (cin>>c>>s>>q && (c||s||q)) { if (cse > 1) cout<> e.x >> e.y >> e.d; } sort(eds, eds+s); int cnt = 0; for (int i=0; i>x>>y; int r = dfs(x, y); if (r<0) cout<<"no path\n"; else cout << r << endl; } } }