제출 #758981

#제출 시각아이디문제언어결과실행 시간메모리
758981BentoOreoVoting Cities (NOI22_votingcity)C++14
5 / 100
8 ms980 KiB
#include <bits/stdc++.h> using namespace std; using ll = long long; using pii = pair<int,int>; using pll = pair<long,long>; const ll INF = numeric_limits<ll>::max(); struct edge{ ll v; ll weight; }; ll solve(vector<vector<edge> > adj,int src, int voting, int n, int e){ vector<ll> distance(n,numeric_limits<ll>::max()); vector<bool> vis(n,false); priority_queue<pll, vector<pll>, greater<pll>> pq; pq.push({0, src}); distance[src] = 0; while(!pq.empty()){ pll stuff = pq.top(); pq.pop();//remove for later ll node = stuff.second;// weight, node pairing if(!vis[node]){ //scan each neighbor for(edge &e : adj[node]){ if(distance[node] + e.weight < distance[e.v]){ distance[e.v] = distance[node] + e.weight; pq.push({distance[e.v],e.v}); } } vis[node] = true; } } if(distance[voting] == INF){ return -1; } else { return distance[voting]; } } int main(){ ll n, e, k;//nodes, edge, voting cities cin >> n >> e >> k; vector<vector<edge> > adj(n); if(k == 1){ int voting; cin >> voting; for(int i = 0; i < e; i++){ ll u,v,w; cin >> u >> v >> w; adj[u].push_back({v,w}); } int q; cin >> q; if(q == 1){ int src; ll ticketprice; cin >> src; unordered_set<ll> TRASH; for(int i = 0; i < 5; i++){ cin >> ticketprice; TRASH.insert(ticketprice); } if(TRASH.size() == 1 && *TRASH.begin() == -1){ ll ans = solve(adj,src,voting,n,e); cout << ans << endl; } else { cout << "I wasn't made for this :(" << endl; } } else { cout << "I wasn't made for this :(" << endl; } } else { cout << "I wasn't made for this :(" << endl; } }
#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...
#Verdict Execution timeMemoryGrader output
Fetching results...