Submission #334484

#TimeUsernameProblemLanguageResultExecution timeMemory
334484beksultan04Evacuation plan (IZhO18_plan)C++14
23 / 100
4073 ms31852 KiB
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define pii pair<int,int>
#define OK puts("OK");
#define fr first
#define sc second
#define ret return
#define scan1(a) scanf("%lld",&a);
#define scan2(a,b) scanf("%lld %lld",&a, &b);
#define scan3(a,b,c) scanf("%lld %lld %lld",&a,&b,&c);
#define all(s) s.begin(),s.end()
#define pb push_back
#define endi puts("");
const int N = 1e5+12,INF=1e9+7;
int dist[N],n,yy,ans;
vector <pii> g[N];
bool is[N];
set <pii> s;
void fun(){
    int i,j,k;
    while (!s.empty()){

        pii x = *s.begin();
        s.erase(s.begin());
        for (i=0;i<g[x.sc].size();++i){
            if (dist[g[x.sc][i].fr] > dist[x.sc]+g[x.sc][i].sc){
                s.erase({dist[g[x.sc][i].fr],g[x.sc][i].fr});
                dist[g[x.sc][i].fr] = dist[x.sc]+g[x.sc][i].sc;
                s.insert({dist[g[x.sc][i].fr],g[x.sc][i].fr});
            }
        }
    }
}
vector <int> v;
void dfs(int x,int mn){
    int i;
    v.pb(x);
    if (ans > mn){
        v.pop_back();
        ret ;
    }
    if (x == yy){
        ans=max(ans,mn);
        v.pop_back();
        ret ;
    }
    for (i=0;i<g[x].size();++i){
        if (is[g[x][i].fr]==0){
            is[g[x][i].fr]=1;
            dfs(g[x][i].fr,min(mn,dist[g[x][i].fr]));
            is[g[x][i].fr]=0;
        }
    }
    v.pop_back();
}

main(){
    int m,i,j;
    scan2(n,m)
    for (i=1;i<=n;++i)dist[i]=INF;
    while (m--){
        int x,y,z;
        scan3(x,y,z)
        g[x].pb({y,z});
        g[y].pb({x,z});
    }
    scan1(m)
    while (m--){
        int x;
        scan1(x)
        dist[x] = 0;
        s.insert({0,x});
    }
    fun();
    scan1(m)
    if (m == 1 || n <= 15){
        while (m--){
            ans = 0;
            int x;
            scan2(x,yy)
            is[x]=1;
            dfs(x,dist[x]);
            is[x]=0;
            cout <<ans<<"\n";
        }
    }

    else
        while (m--){
            int x,y;
            scan2(x,y)
            cout <<min(dist[x],dist[y])<<"\n";
        }
}


Compilation message (stderr)

plan.cpp: In function 'void fun()':
plan.cpp:26:19: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   26 |         for (i=0;i<g[x.sc].size();++i){
      |                  ~^~~~~~~~~~~~~~~
plan.cpp:21:11: warning: unused variable 'j' [-Wunused-variable]
   21 |     int i,j,k;
      |           ^
plan.cpp:21:13: warning: unused variable 'k' [-Wunused-variable]
   21 |     int i,j,k;
      |             ^
plan.cpp: In function 'void dfs(long long int, long long int)':
plan.cpp:48:15: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   48 |     for (i=0;i<g[x].size();++i){
      |              ~^~~~~~~~~~~~
plan.cpp: At global scope:
plan.cpp:58:6: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   58 | main(){
      |      ^
plan.cpp: In function 'int main()':
plan.cpp:59:13: warning: unused variable 'j' [-Wunused-variable]
   59 |     int m,i,j;
      |             ^
plan.cpp:10:25: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   10 | #define scan2(a,b) scanf("%lld %lld",&a, &b);
      |                    ~~~~~^~~~~~~~~~~~~~~~~~~~
plan.cpp:60:5: note: in expansion of macro 'scan2'
   60 |     scan2(n,m)
      |     ^~~~~
plan.cpp:11:27: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   11 | #define scan3(a,b,c) scanf("%lld %lld %lld",&a,&b,&c);
      |                      ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~
plan.cpp:64:9: note: in expansion of macro 'scan3'
   64 |         scan3(x,y,z)
      |         ^~~~~
plan.cpp:9:23: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
    9 | #define scan1(a) scanf("%lld",&a);
      |                  ~~~~~^~~~~~~~~~~
plan.cpp:68:5: note: in expansion of macro 'scan1'
   68 |     scan1(m)
      |     ^~~~~
plan.cpp:9:23: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
    9 | #define scan1(a) scanf("%lld",&a);
      |                  ~~~~~^~~~~~~~~~~
plan.cpp:71:9: note: in expansion of macro 'scan1'
   71 |         scan1(x)
      |         ^~~~~
plan.cpp:9:23: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
    9 | #define scan1(a) scanf("%lld",&a);
      |                  ~~~~~^~~~~~~~~~~
plan.cpp:76:5: note: in expansion of macro 'scan1'
   76 |     scan1(m)
      |     ^~~~~
plan.cpp:10:25: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   10 | #define scan2(a,b) scanf("%lld %lld",&a, &b);
      |                    ~~~~~^~~~~~~~~~~~~~~~~~~~
plan.cpp:81:13: note: in expansion of macro 'scan2'
   81 |             scan2(x,yy)
      |             ^~~~~
plan.cpp:10:25: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   10 | #define scan2(a,b) scanf("%lld %lld",&a, &b);
      |                    ~~~~~^~~~~~~~~~~~~~~~~~~~
plan.cpp:92:13: note: in expansion of macro 'scan2'
   92 |             scan2(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...