Submission #426384

#TimeUsernameProblemLanguageResultExecution timeMemory
426384dualityFrom Hacks to Snitches (BOI21_watchmen)C++11
50 / 100
6076 ms147324 KiB
#include <bits/stdc++.h> using namespace std; #define mp make_pair #define pb push_back typedef long long int LLI; typedef vector<int> vi; typedef pair<int,int> pii; typedef vector<pii> vpii; vi adjList[250000]; pair<int,pii> p[250000]; bool comp(int a,int b) { return p[a] < p[b]; } int pos[250000]; vector<LLI> dist[250000]; priority_queue<pair<LLI,int> > H; int relax(int u,LLI d) { if ((dist[u][d % p[u].first] == -1) || (d < dist[u][d % p[u].first])) { dist[u][d % p[u].first] = d; H.push(mp(-d,u)); } return 0; } int done[250000],done2[250000]; int main() { int i,j; int N,M,K; int u,v,l; scanf("%d %d",&N,&M); for (i = 0; i < M; i++) { scanf("%d %d",&u,&v); u--,v--; adjList[u].pb(v); adjList[v].pb(u); } scanf("%d",&K); for (i = 0; i < K; i++) { scanf("%d",&l); for (j = 0; j < l; j++) scanf("%d",&v),p[v-1] = mp(l,mp(j,i)); } for (i = 0; i < N; i++) { if (p[i].first == 0) p[i].first = 1; dist[i].resize(p[i].first); fill(dist[i].begin(),dist[i].end(),-1); } for (i = 0; i < N; i++) { sort(adjList[i].begin(),adjList[i].end(),comp); while ((pos[i] < adjList[i].size()) && (p[adjList[i][pos[i]]].first == 1)) pos[i]++; } dist[0][0] = 0,H.push(mp(0,0)); while (!H.empty()) { int u = H.top().second; LLI d = -H.top().first; H.pop(); if (d > dist[u][d % p[u].first]) continue; else if (u == N-1) { printf("%lld\n",d); return 0; } if ((p[u].first == 1) || (((d+1) % p[u].first) != p[u].second.first)) relax(u,d+1); for (i = done[u] ? pos[u]:0; i < adjList[u].size(); i++) { int v = adjList[u][i]; if (p[v].first == 1) relax(v,d+1); else if (p[u].first == 1) { if (done2[v]) continue; else { for (j = 0; j < p[v].first; j++) { LLI d2 = d+j+1; if ((d2 % p[v].first) != p[v].second.first) relax(v,d2); } done2[v] = 1; } } else if (p[u].second.second == p[v].second.second) { if (((d+1) % p[v].first) == p[v].second.first) continue; if (((d % p[v].first) == p[v].second.first) && (((d+1) % p[u].first) == p[u].second.first)) continue; relax(v,d+1); } else { for (j = 0; j < p[v].first; j++) { LLI d2 = d+(LLI) j*p[u].first+1; if ((d2 % p[v].first) != p[v].second.first) relax(v,d2); } } } done[u] = 1; } printf("impossible\n"); return 0; }

Compilation message (stderr)

watchmen.cpp: In function 'int main()':
watchmen.cpp:50:24: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   50 |         while ((pos[i] < adjList[i].size()) && (p[adjList[i][pos[i]]].first == 1)) pos[i]++;
      |                 ~~~~~~~^~~~~~~~~~~~~~~~~~~
watchmen.cpp:64:40: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   64 |         for (i = done[u] ? pos[u]:0; i < adjList[u].size(); i++) {
      |                                      ~~^~~~~~~~~~~~~~~~~~~
watchmen.cpp:30:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   30 |     scanf("%d %d",&N,&M);
      |     ~~~~~^~~~~~~~~~~~~~~
watchmen.cpp:32:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   32 |         scanf("%d %d",&u,&v);
      |         ~~~~~^~~~~~~~~~~~~~~
watchmen.cpp:37:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   37 |     scanf("%d",&K);
      |     ~~~~~^~~~~~~~~
watchmen.cpp:39:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   39 |         scanf("%d",&l);
      |         ~~~~~^~~~~~~~~
watchmen.cpp:40:38: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   40 |         for (j = 0; j < l; j++) scanf("%d",&v),p[v-1] = mp(l,mp(j,i));
      |                                 ~~~~~^~~~~~~~~
#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...