Submission #170694

#TimeUsernameProblemLanguageResultExecution timeMemory
170694juggernautEvacuation plan (IZhO18_plan)C++14
0 / 100
4049 ms16300 KiB
//Just try and the idea will come!
#include<bits/stdc++.h>
#define int long long int
using namespace std;
int n,m,i,x,y,z,mn[100001],vis[100001],e,res;
vector<vector<pair<int,int>>>g(100001);
void update(int v){
    for(auto to:g[v]){
        if(mn[v]+to.second<mn[to.first]){
            mn[to.first]=mn[v]+to.second;
            update(to.first);
        }
    }
}
void dfs(int v){
    if(vis[v])return;
    vis[v]=1;
    res=min(res,mn[v]);
    if(v==y)return;
    for(auto to:g[v])dfs(to.first);
    vis[v]=0;
}
main(){
    scanf("%lld%lld",&n,&m);
    for(i=1;i<=n;i++)mn[i]=1e15;
    while(m--){
        scanf("%lld%lld%lld",&x,&y,&z);
        g[x].push_back({y,z});
        g[y].push_back({x,z});
    }
    scanf("%lld",&m);
    while(m--){
        scanf("%lld",&x);
        mn[x]=0;
        update(x);
    }
    scanf("%lld",&m);
    while(m--){
        scanf("%lld%lld",&x,&y);
        for(i=1;i<=n;i++)vis[i]=0;
        e=1;
        res=1e15;
        dfs(x);
        printf("%lld\n",res);
    }
}

Compilation message (stderr)

plan.cpp:23:6: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
 main(){
      ^
plan.cpp: In function 'int main()':
plan.cpp:24:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%lld%lld",&n,&m);
     ~~~~~^~~~~~~~~~~~~~~~~~
plan.cpp:27:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%lld%lld%lld",&x,&y,&z);
         ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
plan.cpp:31:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%lld",&m);
     ~~~~~^~~~~~~~~~~
plan.cpp:33:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%lld",&x);
         ~~~~~^~~~~~~~~~~
plan.cpp:37:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%lld",&m);
     ~~~~~^~~~~~~~~~~
plan.cpp:39:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%lld%lld",&x,&y);
         ~~~~~^~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...