답안 #151773

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
151773 2019-09-04T16:09:56 Z gs18065 Alternative Mart (FXCUP2_mart) C++14
0 / 1
9 ms 5240 KB
#include <bits/stdc++.h>
#define N 50005
#define M 1000003
#define INF 2000000009
#define LINF 9000000000000000009
#define fi first
#define se second
#define eb emplace_back
#define lb lower_bound
#define all(x) (x).begin(),(x).end()
#define uniqv(x) (x).erase(unique(all(x)),(x).end())
#define fastio ios::sync_with_stdio(false);cin.tie(0)
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<pll,int> tri;

int n,m,k,q,s[N],cnt;
vector<pii> net[N];
vector<pll> dist[N];

void dijkstra(){
	priority_queue<tri,vector<tri>,greater<tri> > Q;
	for(int i=1;i<=n;i++){
		for(int j=0;j<cnt;j++) dist[i].eb(LINF,0);
	}
	for(int i=0;i<k;i++){
		Q.push({{0,s[i]},s[i]});
		dist[s[i]][0]={0,s[i]};
	}
	while(!Q.empty()){
		tri p=Q.top();
		Q.pop();
		int now=p.fi.se,from=p.se;
		ll cost=p.fi.fi;
		if(dist[now][cnt-1].fi<cost) continue;
		for(auto i:net[now]){
			int next=i.fi;
			ll nextcost=cost+i.se;
			bool c=true;
			vector<pll> temp;
			for(int i=0;i<cnt;i++){
				if(dist[next][i].fi>=nextcost){
					if(c) temp.eb(nextcost,from);
					if(dist[next][i].se!=from) temp.eb(dist[next][i]);
					c=false;
				}
				else temp.eb(dist[next][i]);
			}
			dist[next]=temp;
			if(c) continue;
			Q.push({{nextcost,next},from});
		}
	}
	return;
}
int main(){
	fastio;
	cin>>n>>m>>k>>q;
	for(int i=0;i<k;i++){
		cin>>s[i];
	}
	cnt=min(k-1,10);
	cnt=2*cnt;
	for(int i=0,t1,t2,val;i<m;i++){
		cin>>t1>>t2>>val;
		net[t1].eb(t2,val);
		net[t2].eb(t1,val);
	}	
	dijkstra();
	while(q--){
		int st,num;
		cin>>st>>num;
		vector<bool> chk(n+1,false);
		for(int i=0,t;i<num;i++){
			cin>>t;
			chk[t]=true;
		}
		ll ans1,ans2=LINF;
		for(int i=0;i<cnt;i++){
			if(chk[dist[st][i].se]) continue;
			if(dist[st][i].fi<ans2||(dist[st][i].fi==ans2&&dist[st][i].se<ans1)){
				ans1=dist[st][i].fi;
				ans2=dist[st][i].se;
			}
		}
		cout<<ans2<<" "<<ans1<<"\n";
	}
	return 0;
}

Compilation message

mart.cpp: In function 'int main()':
mart.cpp:83:49: warning: 'ans1' may be used uninitialized in this function [-Wmaybe-uninitialized]
    if(dist[st][i].fi<ans2||(dist[st][i].fi==ans2&&dist[st][i].se<ans1)){
                            ~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Runtime error 9 ms 5240 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -