Submission #406207

#TimeUsernameProblemLanguageResultExecution timeMemory
406207tqbfjotldFrom Hacks to Snitches (BOI21_watchmen)C++14
0 / 100
5987 ms248152 KiB
#include <bits/stdc++.h> using namespace std; #define int long long int special[250005]; vector<pair<int,int> > orig; vector<int> routes[2755]; int cnt = 1; vector<int> nodes[250005]; vector<int> new_adjl[250005]; int dist[250005]; int tt[250005]; pair<int,int> rev[250005]; main(){ int n,m; scanf("%lld%lld",&n,&m); for (int x = 0; x<m; x++){ int a,b; scanf("%lld%lld",&a,&b); orig.push_back({a,b}); } int K; scanf("%lld",&K); for (int x = 0; x<K; x++){ int l; scanf("%lld",&l); vector<int> stuff; for (int y = 0; y<l; y++){ int a; scanf("%lld",&a); stuff.push_back(a); special[a] = l; tt[a] = y; } } for (int x = 1; x<=n; x++){ for (int y = 0; y<special[x]; y++){ rev[cnt] = {y,special[x]}; nodes[x].push_back(cnt++); } if (special[x]==0){ rev[cnt] = {0,0}; nodes[x].push_back(cnt++); } } for (auto x : orig){ if (special[x.first]&&special[x.second]){ int l = special[x.first]; for (int t = 0; t<l; t++){ if (tt[x.first]!=t && tt[x.second]!=(t+1)%l && (!(tt[x.first]==(t+1)%l && tt[x.second]==t))) new_adjl[nodes[x.first][t]].push_back(nodes[x.second][(t+1)%l]); if (tt[x.second]!=t && tt[x.first]!=(t+1)%l && (!(tt[x.second]==(t+1)%l && tt[x.first]==t))) new_adjl[nodes[x.second][t]].push_back(nodes[x.first][(t+1)%l]); } } else if (special[x.first]){ int l = special[x.first]; for (int t = 0; t<l; t++){ if (tt[x.first]!=t) new_adjl[nodes[x.first][t]].push_back(nodes[x.second][0]); if (tt[x.first]!=(t+1)%l) new_adjl[nodes[x.second][0]].push_back(nodes[x.first][(t+1)%l]); } } else if (special[x.second]){ int l = special[x.second]; for (int t = 0; t<l; t++){ if (tt[x.second]!=(t+1)%l) new_adjl[nodes[x.first][0]].push_back(nodes[x.second][(t+1)%l]); if (tt[x.second]!=t) new_adjl[nodes[x.second][t]].push_back(nodes[x.first][0]); } } else{ new_adjl[nodes[x.first][0]].push_back(nodes[x.second][0]); new_adjl[nodes[x.second][0]].push_back(nodes[x.first][0]); } } for (int x = 1; x<=n; x++){ if (special[x]){ for (int t = 0; t<special[x]; t++){ new_adjl[nodes[x][t]].push_back(nodes[x][(t+1)%special[x]]); } } } memset(dist,-1,sizeof(dist)); priority_queue<pair<int,int>,vector<pair<int,int> >,greater<pair<int,int> > > q; q.push({0,nodes[1][0]}); while (!q.empty()){ int node = q.top().second; int d = q.top().first; q.pop(); if (dist[node]!=-1) continue; if (rev[node].second){ if (d%rev[node].second!=rev[node].first){ int del = (rev[node].first-d)%rev[node].second; if (del<0) del += rev[node].second; d += del; q.push({d,node}); continue; } } //printf("node %lld, %lld\n",node,d); dist[node] = d; for (auto x : new_adjl[node]){ q.push({d+1,x}); } } int ans = dist[nodes[n][0]]; printf(ans==-1?"impossible":"%lld",ans); }

Compilation message (stderr)

watchmen.cpp:16:2: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   16 |  main(){
      |  ^~~~
watchmen.cpp: In function 'int main()':
watchmen.cpp:18:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   18 |     scanf("%lld%lld",&n,&m);
      |     ~~~~~^~~~~~~~~~~~~~~~~~
watchmen.cpp:21:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   21 |         scanf("%lld%lld",&a,&b);
      |         ~~~~~^~~~~~~~~~~~~~~~~~
watchmen.cpp:25:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   25 |     scanf("%lld",&K);
      |     ~~~~~^~~~~~~~~~~
watchmen.cpp:28:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   28 |         scanf("%lld",&l);
      |         ~~~~~^~~~~~~~~~~
watchmen.cpp:32:18: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   32 |             scanf("%lld",&a);
      |             ~~~~~^~~~~~~~~~~
#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...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...