Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

算是给大家一点思路

Posted by 14311210809 at 2015-09-07 11:42:01 on Problem 2263
#include<stdio.h>
#include<algorithm>
#include<string.h>
#include<iostream>
#include<string>
#include<map>
#define N 202
using namespace std;
int tu[N][N];
int n,m;
map<string,int> bb;
int e=1;
int biao[N],vis[N];
void dij(int st) {
    for(int i=1; i<e; i++) biao[i]=0,vis[i]=0;
    biao[st]=2<<20;
    for(int i=1; i<e; i++) {
        int minz=0,u;
        for(int j=1; j<e; j++) if(!vis[j]&&minz<biao[j]) minz=biao[j],u=j;
        vis[u]=1,biao[u]=minz;
        //printf("%d %d\n",u,minz);
        for(int j=1; j<e; j++) if(!vis[j]&&tu[u][j]!=0)
        {
            biao[j]=max(biao[j],min(biao[u],tu[u][j]));//这里就是重点了
        }
        //for(int j=1;j<e;j++) printf("%d%s",biao[j],j==e-1?"\n":" ");
    }
    return ;
}
int main() {
    int ci=1;
    while(scanf("%d%d",&n,&m)!=EOF&&n!=0&&m!=0) {
        e=1;
        bb.clear();
        memset(tu,0,sizeof(tu));
        string u,v;
        int c;
        for(int i=1; i<=m; i++) {
            cin>>u>>v>>c;
            if(bb[u]==0) bb[u]=e++;
            if(bb[v]==0) bb[v]=e++;
            if(tu[bb[u]][bb[v]]<c)tu[bb[u]][bb[v]]=tu[bb[v]][bb[u]]=c;
        }
        cin>>u>>v;
        dij(bb[u]);
        //printf("%d %d\n",bb[u],bb[v]);
        printf("Scenario #%d\n",ci);
        ci++;
        printf("%d tons\n\n",biao[bb[v]]);
    }
    return 0;
}

Followed by:

Post your reply here:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator