# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
100791 | 2019-03-14T13:08:18 Z | Liiiov_V | 경주 (Race) (IOI11_race) | C++17 | 0 ms | 0 KB |
#include <iostream> //#include <fstream> #include <cstdio> #include <algorithm> #include <vector> #include <cstring> #include <string> #include <queue> #include <functional> #include <cmath> #include <map> #include <cstdint> #include <set> #include <unordered_map> using namespace std; //ifstream fin("dq.in"); //ofstream fout("dq.out"); #define ll long long #define ld long double #define mp make_pair #define pb push_back #define fr(i, n) for(ll i=0;i<(ll)n;i++) #define frx(i, x, n) for(ll i=(ll)x;i<(ll)n;i++) #define frb(i, n) for(ll i=(ll)n-1;i>=0;i--) #define frbx(i, x, n) for(ll i=(ll)n-1;i>=(ll)x;i--) const int64_t mod = (ll)1e9 + 7; const int64_t primm = 998244353; ll n, k, h[1000005][2], l[1000005], ans=mod*mod, centr, order[1000005], ans[1000005]; vector<pair<ll, ll>> g[200005]; queue<ll> qu; bool col[1000005]; void dfs(ll x, ll her) { if(g[x].size()==1) { order[x]=1; return; } ll sum=1; fr(i, g[x].size()) { if(g[x][i].first!=her && !col[g[x][i].first]) { dfs(g[x][i].first, x); sum+=order[g[x][i].first]; } } order[x]=sum; return; } void find(ll x) { ll sum=1, mok=0; fr(i, g[x].size()) { dfs(g[x][i].first, x); sum+=order[g[x][i].first]; } centr=x; while(mok==0) { fr(i, g[centr].size()) { if(order[g[centr][i].first]>=sum/2) { centr=g[centr][i].first; break; } if(i==g[centr].size()-1) mok++; } } solve(); fr(i, g[centr].size()) { if(!col[g[centr][i].first]) qu.push(g[centr][i].first); } return; } ll get(ll x) { } void solve() { fr(i, g[centr].size()) { } } int main() { cin>>n>>k; fr(i, k) cin>>h[i][0]>>h[i][1]; fr(i, k) { cin>>l[i]; g[h[i][0]].push_back(mp(h[i][1], l[i])); g[h[i][1]].push_back(mp(h[i][0], l[i])); } qu.push(0); while(!qu.empty()) { ll f=qu.front(); col[f]=true; find(f); } return 0; }