# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
240458 | 2020-06-19T16:52:49 Z | oscarsierra12 | 악어의 지하 도시 (IOI11_crocodile) | C++14 | 0 ms | 0 KB |
#include "crocodile.h" #include <bits/stdc++.h> using namespace std ; const int N = 1e5+2 ; #define ff first #define ss second #define pb push_back const int oo = 1e9+2 ; vector <pair<int,int> > G[N] ; int deg[N] ; int fr[N], sc[N] ; int visit[N] ; int travel_plan(int N, int M, int R[][2], int L[], int K, int P[]) { for ( int i = 0 ; i < N ; ++i ) fr[i] = sc[i] = oo ; for ( int i = 0 ; i < M ; ++i ) G[R[i][0]].pb ( make_pair(R[i][1], L[i]) ), G[R[i][1]].pb ( make_pair(R[i][0], L[i])) ; queue <pair<int,int> > q ; for ( int i = 0 ; i < K ; ++i ) fr[P[i]] = sc[P[i]] = 0, q.push ( make_pair ( 0, P[i] ) ) ; while ( q.size() ) { pair <int,int> u = q.top() ; q.pop() ; if ( visit[ u.ss ] ) continue ; visit[u.ss] = 1 ; for ( auto v:G[u.ss] ) { if ( -u.ff + v.ss < sc[v.ff] ) sc[v.ff] = -u.ff + v.ss ; if ( fr[v.ff] > sc[v.ff] ) swap ( fr[v.ff], sc[v.ff] ) ; deg[v.ff]++ ; if ( deg[v.ff] >= 2 ) q.push ( make_pair(-sc[v.ff], v.ff) ) ; } } return sc[0] ; }