Submission #1161376

#TimeUsernameProblemLanguageResultExecution timeMemory
1161376AgentPenginAirplane (NOI23_airplane)C++20
22 / 100
50 ms15288 KiB
/**
 *    author:  AgentPengin ( Độc cô cầu bại )
 *    created: 23.12.2022 10:08:02
 *    too lazy to update time
**/
#include<bits/stdc++.h>

#define EL '\n'
#define fi first
#define se second
#define NAME "TASK"
#define ll long long
#define lcm(a,b) (a/gcd(a,b))*b
#define db(val) "["#val" = " << (val) << "] "
#define bend(v) (v).begin(),(v).end()
#define sz(v) (int)(v).size()
#define ex exit(0)

using namespace std;

const ll mod = 1e9 + 7;
const int inf = 0x1FFFFFFF;
const int MAXN = 2e5 + 5;

int n, m;
vector<int> adj[MAXN];
int a[MAXN];
vector<pair<int,int>> edges;

int dist[2][MAXN];

void dijkstra(int startNode, int id) {
	memset(dist[id], 0x3f, sizeof dist[id]);
	dist[id][startNode] = 0;
	priority_queue<pair<int,int>,vector<pair<int,int>>, greater<pair<int,int>>> pq;
	pq.push(make_pair(0, startNode));
	
	while(!pq.empty()) {
		int du = pq.top().fi;
		int u = pq.top().se;
		pq.pop();
		if (du != dist[id][u]) continue;
		for (auto v : adj[u]) {
			if (max(du + 1, a[v]) < dist[id][v]) {
				dist[id][v] = max(du + 1, a[v]);
				pq.push({dist[id][v], v});
			}
		}
	}
}

signed main() {
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    if (ifstream(NAME".inp")) {
        freopen(NAME".inp","r",stdin);
        freopen(NAME".out","w",stdout);
    }
    cin >> n >> m;
    for (int i = 1;i <= n;i++) cin >> a[i];
    for (int i = 1;i <= m;i++) {
    	int u,v; cin >> u >> v;
    	edges.push_back(make_pair(u,v));
    	adj[u].push_back(v);
    	adj[v].push_back(u);
    }
    dijkstra(1, 0);
    dijkstra(n, 1);
    int ans = 1e9;
    for (int u = 1;u <= n;u++) {
    	ans = min(ans, 2 * max(dist[0][u], dist[1][u]));
    }
    for (auto [u, v] : edges) {
    	ans = min(ans, 2 * max(dist[0][u], dist[1][v]) + 1);
    }
    cout << ans;
    
    cerr << "\nTime elapsed: " << 1000 * clock() / CLOCKS_PER_SEC << "ms\n";
    return 0;
}
// agent pengin wants to take apio (with anya-san)

Compilation message (stderr)

Main.cpp: In function 'int main()':
Main.cpp:55:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   55 |         freopen(NAME".inp","r",stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
Main.cpp:56:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   56 |         freopen(NAME".out","w",stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...