Submission #1040370

#TimeUsernameProblemLanguageResultExecution timeMemory
1040370vjudge1Evacuation plan (IZhO18_plan)C++14
41 / 100
4033 ms30352 KiB
#include<bits/stdc++.h> using namespace std ; #define maxn 500009 #define ll long long #define pb push_back #define fi first #define se second #define left id<<1 #define right id<<1|1 #define re exit(0); #define _lower(x) lower_bound(v.begin(),v.end(),x)-v.begin()+1 const int mod = 1e9+7 ; const int INF = 1e9 ; typedef vector<int> vi ; typedef pair<int,int> pii ; typedef vector<pii> vii ; template < typename T > void chkmin ( T &a , T b ) { if ( a > b ) a = b ; } template < typename T > void chkmax ( T &a , T b ) { if ( a < b ) a = b ; } void add ( int &a , int b ) { a += b ; if ( a >= mod ) a -= mod ; if ( a < 0 ) a += mod ; } void rf () { freopen ("bai1.inp","r",stdin) ; } int _pow ( int a , int n ) { if ( n == 0 ) return 1 ; int res = _pow (a,n/2) ; if ( n % 2 ) return 1ll*res*res%mod*a%mod ; else return 1ll*res*res%mod ; } int n , m , nq ; vii adjList [maxn] ; int k ; int f [maxn] ; struct shape { int u,d ; bool operator < ( const shape &o ) const { return d > o.d ; } }; int d [maxn] ; void dijkstra () { priority_queue <shape> S ; memset(d,0x3f,sizeof d) ; for ( int i = 1 ; i <= k ; i ++ ) S . push ({f[i],d[f[i]]=0}) ; while ( !S.empty() ) { shape t = S.top() ; S.pop() ; int u = t.u ; if ( d[u] != t.d ) continue ; for ( auto x : adjList [u] ) { int v = x.fi , w = x.se ; if ( d [v] > d [u] + w ) { d [v] = d[u] + w ; S . push ({v,d[v]}) ; } } } } pii p [maxn] ; bool cmp ( pii u , pii v ) { return u.fi > v.fi ; } int lab [maxn] ; int find ( int u ) { return (lab[u]<0) ? u : lab[u] = find(lab[u]) ; } void uni ( int u , int v ) { if ((u=find(u)) == (v=find(v))) return ; if ( lab [u] > lab [v] ) swap (u,v) ; lab [u] += lab [v] ; lab [v] = u ; } int main () { ios_base::sync_with_stdio(0); cin.tie(0);cout.tie(0); // rf () ; cin >> n >> m ; for ( int i = 1 ; i <= m ; i ++ ) { int u,v,w ; cin >> u >> v >> w ; adjList [u] . pb ({v,w}) ; adjList [v] . pb ({u,w}) ; } cin >> k ; for ( int i = 1 ; i <= k ; i ++ ) cin >> f [i] ; dijkstra () ; // for ( int i = 1 ; i <= n ; i ++ ) cout << d [i] << " " ; re for ( int i = 1 ; i <= n ; i ++ ) p [i] = {d[i],i} ; sort (p+1,p+n+1,cmp) ; cin >> nq ; while ( nq -- ) { int x,y ; cin >> x >> y ; for ( int i = 1 ; i <= n ; i ++ ) lab [i] = -1 ; int res ; for ( int i = 1 ; i <= n ; i ++ ) { int u = p[i].se ; for ( auto v : adjList [u] ) { if ( d [v.fi] >= d [u] ) uni (u,v.fi) ; } if ( find(x) == find(y) ) { res = p[i].fi ; break ; } } cout << res << "\n" ; } }

Compilation message (stderr)

plan.cpp: In function 'void rf()':
plan.cpp:31:10: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   31 |  freopen ("bai1.inp","r",stdin) ;
      |  ~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
plan.cpp: In function 'int main()':
plan.cpp:134:18: warning: 'res' may be used uninitialized in this function [-Wmaybe-uninitialized]
  134 |   cout << res << "\n" ;
      |                  ^~~~
#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...