답안 #151781

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
151781 2019-09-04T16:59:43 Z gs18065 Alternative Mart (FXCUP2_mart) C++14
0 / 1
95 ms 11880 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<ll,pll> tri;

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

void dijkstra(){
	priority_queue<tri,vector<tri>,greater<tri> > Q;
	for(int i=0;i<k;i++){
		Q.push({0,{s[i],s[i]}});
	}
	while(!Q.empty()){
		tri p=Q.top();
		Q.pop();
		int now=p.se.se,from=p.se.fi;
		ll cost=p.fi;
		if(vis[now].size()==11||vis[now].find(from)!=vis[now].end()) continue;
		vis[now].insert(from);
		dist[now].eb(cost,from);
		for(auto i:net[now]){
			int next=i.fi;
			ll nextcost=cost+i.se;
			Q.push({nextcost,{from,next}});
		}
	}
	return;
}
int main(){
	fastio;
	cin>>n>>m>>k>>q;
	for(int i=0;i<k;i++){
		cin>>s[i];
	}
	for(int i=0,t1,t2;i<m;i++){
		ll val;
		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=LINF,ans2=LINF;
		for(int i=0;i<dist[st].size();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:67:16: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   for(int i=0;i<dist[st].size();i++){
               ~^~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 4984 KB Output is correct
2 Correct 6 ms 5112 KB Output is correct
3 Correct 6 ms 5112 KB Output is correct
4 Correct 7 ms 4984 KB Output is correct
5 Correct 7 ms 5112 KB Output is correct
6 Correct 7 ms 5112 KB Output is correct
7 Correct 12 ms 5496 KB Output is correct
8 Correct 10 ms 5496 KB Output is correct
9 Incorrect 95 ms 11880 KB Output isn't correct
10 Halted 0 ms 0 KB -