Submission #74346

#TimeUsernameProblemLanguageResultExecution timeMemory
74346khsoo01Alternative Mart (FXCUP2_mart)C++11
1 / 1
546 ms143416 KiB
#include<bits/stdc++.h> #define X first #define Y second using namespace std; typedef pair<int,int> pii; const int inf = 1e9; int n, m, k, q, c[50005], vis[50005], ts; pii d[50005][12]; vector<pii> adj[50005]; priority_queue<pair<pii,int> > pq; bool upd (int I, pii V) { for(int i=0;i<11;i++) { if(d[I][i] < V) { pii T = d[I][i]; d[I][i] = V; for(int j=i+1;j<11;j++) { if(T.Y == V.Y) return true; swap(d[I][j], T); } return true; } if(d[I][i].Y == V.Y) return false; } return false; } int main() { scanf("%d%d%d%d",&n,&m,&k,&q); for(int i=1;i<=n;i++) { for(int j=0;j<11;j++) d[i][j] = pii(-inf, 1); } for(int i=1;i<=k;i++) { int T; scanf("%d",&T); upd(T, pii(0, -T)); pq.push({pii(0, -T), T}); } for(int i=1;i<=m;i++) { int A, B, C; scanf("%d%d%d",&A,&B,&C); adj[A].push_back({B, C}); adj[B].push_back({A, C}); } while(!pq.empty()) { pii V; int I; tie(V, I) = pq.top(); pq.pop(); if(c[I] == 11 || d[I][c[I]] != V) continue; c[I]++; for(auto &T : adj[I]) { int A, B; tie(A, B) = T; pii X = pii(V.X-B, V.Y); if(upd(A, X)) pq.push({X, A}); } } while(q--) { int A, M; ts++; scanf("%d%d",&A,&M); for(int i=0;i<M;i++) { int T; scanf("%d",&T); vis[T] = ts; } for(int i=0;i<11;i++) { if(vis[-d[A][i].Y] == ts) continue; printf("%d %d\n",-d[A][i].Y,-d[A][i].X); break; } } }

Compilation message (stderr)

mart.cpp: In function 'int main()':
mart.cpp:32:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d%d%d%d",&n,&m,&k,&q);
  ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
mart.cpp:38:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d",&T);
   ~~~~~^~~~~~~~~
mart.cpp:44:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d%d%d",&A,&B,&C);
   ~~~~~^~~~~~~~~~~~~~~~~~~
mart.cpp:60:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d%d",&A,&M);
   ~~~~~^~~~~~~~~~~~~~
mart.cpp:63:9: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
    scanf("%d",&T);
    ~~~~~^~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...