http://acm.timus.ru/problem.aspx?space=1&num=1210
水题
代码:
#include<iostream> #include<cstdio> #include<cstring> #include<string> #include<vector> #include<queue> #include<map> #include<stack> #include<algorithm> #include<cmath> using namespace std; //#pragma comment(linker,"/STACK:1000000000,1000000000") #define LL long long const int INF=0x3f3f3f3f; const int N=35; int dist[N][N]; int main() { int n; while(cin>>n) { dist[0][1]=0; for(int i=1;i<N;++i) for(int j=0;j<N;++j) dist[i][j]=INF; int ans=INF; int m; char c; for(int i=1;i<=n;++i) { cin>>m; for(int j=1;j<=m;++j) { int pre,d; while(cin>>pre) { if(pre==0) break; cin>>d; dist[i][j]=min(dist[i][j],dist[i-1][pre]+d); if(i==n) ans=min(ans,dist[i][j]); } } if(i<n) cin>>c; } cout<<ans<<endl; } return 0; }