Created
March 3, 2017 03:32
-
-
Save ia7ck/fd7b138581900c7918c3688257305625 to your computer and use it in GitHub Desktop.
ARC 056-B 駐車場
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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