Submission #893388

# Submission time Handle Problem Language Result Execution time Memory
893388 2023-12-27T04:04:07 Z vjudge1 Airplane (NOI23_airplane) C++17
100 / 100
485 ms 64880 KB
#include<bits/stdc++.h>
#define taskname "ONEPIECE"
#define el '\n'
#define fi first
#define sc second
#define pii pair<int, int>
#define all(v) v.begin(), v.end()
#define int ll
using namespace std;
using ll=long long;
using ull=unsigned long long;
using ld=long double;
#define Faster ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
using namespace std;
const int maxn=1e6+2;
const int mod=1e9+7;
const int inf=1e15;
int n,m,a[maxn],dp1[maxn],dp2[maxn],d[maxn],vis[maxn];
vector<int> adj[maxn];
void dijkstra(int x)
{
    priority_queue<pii> pq;
    pq.push({0,x});
    for(int i=1;i<=n;i++) vis[i]=0;
    while(!pq.empty())
    {
        int x=pq.top().sc;
        int dis=-pq.top().fi;
//        cout<<"!"<<x<<" "<<dis<<"\n";
        pq.pop();
        if(vis[x]) continue;
        d[x]=dis;
        vis[x]=1;
        for(int y:adj[x])
        {
            pq.push({-max(d[x]+1,a[y]),y});
        }
    }
}
signed main()
{
    if (fopen(taskname".INP","r"))
    {
        freopen(taskname".INP","r",stdin);
        freopen(taskname".OUT","w",stdout);
    }
    Faster
    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;
        adj[u].push_back(v);
        adj[v].push_back(u);
    }
    dijkstra(1);
    for(int i=1;i<=n;i++) dp1[i]=d[i];
    dijkstra(n);
    for(int i=1;i<=n;i++) dp2[i]=d[i];
    int res=inf;
    for(int i=1;i<=n;i++)
    {
        res=min(res,2*max(dp1[i],dp2[i]));
    }
    for(int i=1;i<=n;i++)
    {
        for(int j:adj[i])
        {
            res=min(res,2*max(dp1[i],dp2[j])+1);
        }
    }
    cout<<res<<"\n";
//    for(int i=1;i<=n;i++)
//    {
//        cout<<i<<":"<<dp1[i]<<" "<<dp2[i]<<"\n";
//    }
}

Compilation message

Main.cpp: In function 'int main()':
Main.cpp:44:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   44 |         freopen(taskname".INP","r",stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~
Main.cpp:45:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   45 |         freopen(taskname".OUT","w",stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 8 ms 33372 KB Output is correct
2 Correct 66 ms 47700 KB Output is correct
3 Correct 67 ms 47700 KB Output is correct
4 Correct 67 ms 47696 KB Output is correct
5 Correct 76 ms 47700 KB Output is correct
6 Correct 69 ms 47952 KB Output is correct
7 Correct 69 ms 47740 KB Output is correct
8 Correct 7 ms 33368 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 7 ms 33372 KB Output is correct
2 Correct 6 ms 33444 KB Output is correct
3 Correct 7 ms 33372 KB Output is correct
4 Correct 7 ms 33372 KB Output is correct
5 Correct 7 ms 33372 KB Output is correct
6 Correct 8 ms 33544 KB Output is correct
7 Correct 8 ms 33372 KB Output is correct
8 Correct 8 ms 33372 KB Output is correct
9 Correct 7 ms 33372 KB Output is correct
10 Correct 7 ms 33556 KB Output is correct
11 Correct 7 ms 33372 KB Output is correct
12 Correct 8 ms 33372 KB Output is correct
13 Correct 8 ms 33368 KB Output is correct
14 Correct 9 ms 33628 KB Output is correct
15 Correct 9 ms 33624 KB Output is correct
16 Correct 9 ms 33628 KB Output is correct
17 Correct 9 ms 33668 KB Output is correct
18 Correct 6 ms 33368 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 7 ms 33372 KB Output is correct
2 Correct 6 ms 33444 KB Output is correct
3 Correct 7 ms 33372 KB Output is correct
4 Correct 7 ms 33372 KB Output is correct
5 Correct 7 ms 33372 KB Output is correct
6 Correct 8 ms 33544 KB Output is correct
7 Correct 8 ms 33372 KB Output is correct
8 Correct 8 ms 33372 KB Output is correct
9 Correct 7 ms 33372 KB Output is correct
10 Correct 7 ms 33556 KB Output is correct
11 Correct 7 ms 33372 KB Output is correct
12 Correct 8 ms 33372 KB Output is correct
13 Correct 8 ms 33368 KB Output is correct
14 Correct 9 ms 33628 KB Output is correct
15 Correct 9 ms 33624 KB Output is correct
16 Correct 9 ms 33628 KB Output is correct
17 Correct 9 ms 33668 KB Output is correct
18 Correct 6 ms 33368 KB Output is correct
19 Correct 9 ms 33372 KB Output is correct
20 Correct 9 ms 33372 KB Output is correct
21 Correct 8 ms 33372 KB Output is correct
22 Correct 8 ms 33372 KB Output is correct
23 Correct 8 ms 33372 KB Output is correct
24 Correct 8 ms 33372 KB Output is correct
25 Correct 9 ms 33368 KB Output is correct
26 Correct 9 ms 33372 KB Output is correct
27 Correct 10 ms 33644 KB Output is correct
28 Correct 9 ms 33624 KB Output is correct
29 Correct 9 ms 33628 KB Output is correct
30 Correct 9 ms 33628 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 8 ms 33372 KB Output is correct
2 Correct 66 ms 47700 KB Output is correct
3 Correct 67 ms 47700 KB Output is correct
4 Correct 67 ms 47696 KB Output is correct
5 Correct 76 ms 47700 KB Output is correct
6 Correct 69 ms 47952 KB Output is correct
7 Correct 69 ms 47740 KB Output is correct
8 Correct 7 ms 33368 KB Output is correct
9 Correct 7 ms 33372 KB Output is correct
10 Correct 6 ms 33444 KB Output is correct
11 Correct 7 ms 33372 KB Output is correct
12 Correct 7 ms 33372 KB Output is correct
13 Correct 7 ms 33372 KB Output is correct
14 Correct 8 ms 33544 KB Output is correct
15 Correct 8 ms 33372 KB Output is correct
16 Correct 8 ms 33372 KB Output is correct
17 Correct 7 ms 33372 KB Output is correct
18 Correct 7 ms 33556 KB Output is correct
19 Correct 7 ms 33372 KB Output is correct
20 Correct 8 ms 33372 KB Output is correct
21 Correct 8 ms 33368 KB Output is correct
22 Correct 9 ms 33628 KB Output is correct
23 Correct 9 ms 33624 KB Output is correct
24 Correct 9 ms 33628 KB Output is correct
25 Correct 9 ms 33668 KB Output is correct
26 Correct 6 ms 33368 KB Output is correct
27 Correct 9 ms 33372 KB Output is correct
28 Correct 9 ms 33372 KB Output is correct
29 Correct 8 ms 33372 KB Output is correct
30 Correct 8 ms 33372 KB Output is correct
31 Correct 8 ms 33372 KB Output is correct
32 Correct 8 ms 33372 KB Output is correct
33 Correct 9 ms 33368 KB Output is correct
34 Correct 9 ms 33372 KB Output is correct
35 Correct 10 ms 33644 KB Output is correct
36 Correct 9 ms 33624 KB Output is correct
37 Correct 9 ms 33628 KB Output is correct
38 Correct 9 ms 33628 KB Output is correct
39 Correct 213 ms 48964 KB Output is correct
40 Correct 133 ms 48804 KB Output is correct
41 Correct 147 ms 48732 KB Output is correct
42 Correct 138 ms 48724 KB Output is correct
43 Correct 141 ms 48724 KB Output is correct
44 Correct 141 ms 48716 KB Output is correct
45 Correct 151 ms 48944 KB Output is correct
46 Correct 157 ms 49072 KB Output is correct
47 Correct 146 ms 48724 KB Output is correct
48 Correct 146 ms 48976 KB Output is correct
49 Correct 204 ms 48964 KB Output is correct
50 Correct 197 ms 48960 KB Output is correct
51 Correct 167 ms 48740 KB Output is correct
52 Correct 353 ms 54380 KB Output is correct
53 Correct 326 ms 54292 KB Output is correct
54 Correct 372 ms 55192 KB Output is correct
55 Correct 362 ms 51624 KB Output is correct
56 Correct 476 ms 57816 KB Output is correct
57 Correct 478 ms 57924 KB Output is correct
58 Correct 449 ms 57376 KB Output is correct
59 Correct 458 ms 57700 KB Output is correct
60 Correct 475 ms 64192 KB Output is correct
61 Correct 476 ms 57124 KB Output is correct
62 Correct 428 ms 64088 KB Output is correct
63 Correct 434 ms 64880 KB Output is correct
64 Correct 442 ms 62864 KB Output is correct
65 Correct 456 ms 63936 KB Output is correct
66 Correct 485 ms 57280 KB Output is correct
67 Correct 484 ms 57116 KB Output is correct