Submission #1102383

#TimeUsernameProblemLanguageResultExecution timeMemory
1102383huyngodzzAirplane (NOI23_airplane)C++14
100 / 100
323 ms28868 KiB
///huynhocute123/// #include<bits/stdc++.h> using namespace std; #define S second #define F first #define pii pair<long long ,long long > #define piii pair<int,pair<int,int>> #define pb push_back #define pi M_PI #define FOR(i, a, b) for(int i = a; i <= b; ++i) #define REP(i, a, b) for(int i = b; i >= a; --i) #define ALL(v) v.begin(),v.end() #define inp(name) if(fopen(name, "r")) freopen(name, "r", stdin); #define out(name) if(fopen(name, "w")) freopen(name, "w", stdout); //random_device rd; //mt19937 rng(rd()); //#pragma GCC optimize ("O3") //#pragma GCC optimize ("unroll-loops") //#pragma GCC target("popcnt") //#define int long long const int maxN = 4 * 1e5 + 9; const int modd = 1e9 + 7; const int base = 2309; const long long MAX = 1e16+9; void minimize(int &u, int v){ if(v < u) u = v; } void maximize(int &u, int v){ if(v > u) u = v; } int n, k, t, m, a[maxN]; long long res; long long S[maxN], T[maxN]; int l, r; bool vis[maxN]; vector<int> e[maxN]; priority_queue<pii ,vector<pii> ,greater<pii>>pq; void dt1(int st){ for(int i =1;i <= n ;i++){ S[i] = MAX; T[i] = MAX; } S[1] = 0; pq.push({0 , 1}); while(pq.size()){ long long du =pq.top().F , u = pq.top().S; pq.pop(); if(du != S[u])continue; for(auto x : e[u]){ if(S[x] > max(du + 1, a[x]*1LL) ){ S[x] = max(du + 1, a[x]*1LL); pq.push({S[x], x}); } } } } void dt2(int st){ T[n] = 0; pq.push({0 , n}); while(pq.size()){ long long du =pq.top().F , u = pq.top().S; pq.pop(); if(du != T[u])continue; for(auto x : e[u]){ if(T[x] > max(du + 1, a[x]*1LL) ){ T[x] = max(du + 1, a[x]*1LL); pq.push({T[x], x}); } } } } void solve(){ cin >> n >> m; for(int i =1;i <= n ;i++)cin>> a[i]; for(int i= 1;i <= m ;i++){ cin >> l >> r; e[l].pb(r); e[r].pb(l); } dt1(1); dt2(n); res= MAX; // for(int i =1; i <= n ;i++){ // cout <<i << " " << S[i] << " " << T[i] << '\n'; // } for(int i =1;i <= n ;i++){ res =min(res, max(S[i] , T[i])*2 ); for(auto j : e[i])res =min(res,max(T[i] ,S[j])* 2 + 1 ); } cout << res; } signed main(){ // freopen("name.inp","r",stdin); // freopen("name.out","w",stdout); ios_base::sync_with_stdio(false); cin.tie(0); inp("task.inp"); t = 1; // cin >> t; while( t-- )solve(); }

Compilation message (stderr)

Main.cpp: In function 'int main()':
Main.cpp:13:47: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   13 | #define inp(name) if(fopen(name, "r")) freopen(name, "r", stdin);
      |                                        ~~~~~~~^~~~~~~~~~~~~~~~~~
Main.cpp:100:5: note: in expansion of macro 'inp'
  100 |     inp("task.inp");
      |     ^~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...