Skip to content

Instantly share code, notes, and snippets.

@ia7ck
Created March 3, 2017 03:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ia7ck/fd7b138581900c7918c3688257305625 to your computer and use it in GitHub Desktop.
Save ia7ck/fd7b138581900c7918c3688257305625 to your computer and use it in GitHub Desktop.
ARC 056-B 駐車場
#include<iostream>
#include<vector>
#include<queue>
using namespace std;
typedef pair<int, int> pii;
vector<int> g[2*100000];
int main(){
int N, M, s;
cin>> N>> M>> s;
s--;
for(int i=0; i<M; i++){
int a, b;
cin>> a>> b;
a--; b--;
g[a].push_back(b);
g[b].push_back(a);
}
priority_queue<pii> Q;
Q.push(pii(s, s));
int cost[N];
fill(cost, cost+N, 0);
cost[s]=s;
while(!Q.empty()){
int c, i;
c=Q.top().first;
i=Q.top().second;
Q.pop();
for(int j: g[i]){
int _c=min(c, j);
if(_c>cost[j]){
cost[j]=_c;
Q.push(pii(_c, j));
}
}
}
for(int i=0; i<N; i++){
if(cost[i]>=i) cout<< i+1<< endl;
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment