Submission #1040408

#TimeUsernameProblemLanguageResultExecution timeMemory
1040408vjudge1Evacuation plan (IZhO18_plan)C++14
100 / 100
390 ms71944 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 L [maxn] , R [maxn] ; int x [maxn] , y [maxn] ; vi to_check [maxn] ; 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 ++ ) p [i] = {d[i],i} ; sort (p+1,p+n+1,cmp) ; cin >> nq ; for ( int i = 1 ; i <= nq ; i ++ ) { cin >> x[i] >> y[i] ; L [i] = 1 , R [i] = n ; } while ( true ) { for ( int i = 1 ; i <= n ; i ++ ) to_check[i].clear() ; bool changed = false ; for ( int i = 1 ; i <= nq ; i ++ ) { if ( L [i] != R [i] ) { to_check [(L[i]+R[i])/2] . pb (i) ; changed = true ; } } if ( changed == false ) break ; for ( int i = 1 ; i <= n ; i ++ ) lab [i] = -1 ; 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) ; } for ( auto j : to_check [i] ) { if ( find(x[j]) == find(y[j]) ) R [j] = i ; else L [j] = i+1 ; } } } for ( int i = 1 ; i <= nq ; i ++ ) cout << p[L[i]].fi << "\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) ;
      |  ~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
#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...