PTA L2 - 001

#include
using namespace std;
const int N = 500+5;
int aid[N];
bool flag[N];
int mind[N];
int path[N];
int cnt[N];
int num[N];
typedef pair pii;
vector graph[N];
vector U,V,W;
priority_queue,greater > pq;
void getAnswer(int n, int m,int s,int t){
    memset(mind,127,sizeof(mind));
    memset(flag,0,sizeof(flag));
    memset(path,-1,sizeof(path));
    while(!pq.empty())
            pq.pop();
    for(int i =0 ; i<=n; ++i)
            graph[i].clear();
    for(int i=0; ifirst;
                int w = it->second;
               if(mind[u] +  w  < mind[v]){
                    num[v] = num[u];
                    mind[v] = mind[u] + w;
                    cnt[v] = cnt[u] + aid[v];
                    path[v] = u;
                    pq.push(make_pair(mind[v],v));
               }else if ( mind[u] + w == mind[v]){
                   if(cnt[v]  < cnt[u] + aid[v]){
                        cnt[v] = cnt[u] + aid[v];
                        path[v] = u;
                   }
                   num[v] += num[u];
               }
            }
        }
    }

}
void dfs(int s,int v){
    if(v == s)
        printf("%d",s);
    else{
        dfs(s,path[v]);
        printf(" %d",v);
    }
}
int main()
{
    int n,m,s,t;
    cin>>n>>m>>s>>t;
    for(int i=0; i>aid[i];
    for(int i=0;i>u>>v>>w;
        U.push_back(u);
        V.push_back(v);
        W.push_back(w);
    }
    getAnswer(n,m,s,t);
    printf("%d %d\n",num[t],cnt[t]);
    //dfs(s,t);
    stack sta;
    sta.push(t);
    while(sta.top() != s){
        sta.push(path[sta.top()]);
    }
    //cout<

你可能感兴趣的:(PTA L2 - 001)