diff --git a/src/10/2/P3393.cpp b/src/10/2/P3393.cpp new file mode 100644 index 0000000..b6c8f3b --- /dev/null +++ b/src/10/2/P3393.cpp @@ -0,0 +1,63 @@ +#include +#include +#include +#include +#include +#include +#include +#include +#include +using ll = int64_t; + +const ll maxn = 2e5+5, inf=1e9+7; +ll n,m,k,s,p,q,c[maxn],distb[maxn],dist[maxn]; +std::vector> adj; +std::queue que; +std::bitset isc,isw; + +int main(){ + std::iostream::sync_with_stdio(false); + std::cin.tie(nullptr); + + std::cin>>n>>m>>k>>s>>p>>q; + for(ll i=1;i<=n;i++)distb[i]=inf,dist[i]=inf; + for(ll i=1;i<=k;i++){ + std::cin>>c[i]; + isc[c[i]]=true; + que.push(c[i]); + distb[c[i]]=0; + } + adj.resize(n+1); + for(ll i=1;i<=m;i++){ + ll a,b; + std::cin>>a>>b; + adj[a].emplace_back(b); + adj[b].emplace_back(a); + } + while(que.size()){ + ll u = que.front(); + que.pop(); + for(ll v:adj[u]){ + distb[v]=std::min(distb[v],distb[u]+1); + if(distb[v], std::vector>, std::greater>> pq; + pq.emplace(0,1); + while(pq.size()){ + auto[ss,u] = pq.top(); + pq.pop(); + if(dist[u] +#include +#include +#include +#include + +using ll = int64_t; +struct Station { + int id; + int x, y; +}; + +using State = std::pair; + +const ll INF = 1e18; + +int main() { + + std::ios_base::sync_with_stdio(false); + std::cin.tie(nullptr); + + int n, m; + std::cin >> n >> m; + + std::vector sta(m + 2); + + for (int i = 0; i < m; ++i) { + sta[i].id = i; + std::cin >> sta[i].x >> sta[i].y; + } + + int startx, starty, endx, endy; + std::cin >> startx >> starty >> endx >> endy; + + sta[m].id = m; + sta[m].x = startx; + sta[m].y = starty; + + sta[m + 1].id = m + 1; + sta[m + 1].x = endx; + sta[m + 1].y = endy; + + const int N = m + 2; + const int prenode = 2 * N; + std::vector>> adj(prenode); + + std::vector p(N); + for (int i = 0; i < N; ++i) + p[i] = i; + + std::sort(p.begin(), p.end(), [&](int a, int b) { + if (sta[a].x != sta[b].x) + return sta[a].x < sta[b].x; + return sta[a].y < sta[b].y; + }); + + for (int i = 1; i < N; ++i) { + int uidx = p[i - 1]; + int vidx = p[i]; + + if (sta[uidx].x == sta[vidx].x) { + ll weight = 2LL * (sta[vidx].y - sta[uidx].y); + + adj[uidx].push_back({vidx, (int)weight}); + adj[vidx].push_back({uidx, (int)weight}); + } + } + + std::sort(p.begin(), p.end(), [&](int a, int b) { + if (sta[a].y != sta[b].y) + return sta[a].y < sta[b].y; + return sta[a].x < sta[b].x; + }); + + for (int i = 1; i < N; ++i) { + int uidx = p[i - 1]; + int vidx = p[i]; + + if (sta[uidx].y == sta[vidx].y) { + ll weight = 2LL * (sta[vidx].x - sta[uidx].x); + + adj[uidx + N].push_back({vidx + N, (int)weight}); + adj[vidx + N].push_back({uidx + N, (int)weight}); + } + } + + if (startx == endx) { + adj[m].push_back({m + 1, (int)(2LL * std::abs(starty - endy))}); + adj[m + 1].push_back({m, (int)(2LL * std::abs(starty - endy))}); + } + if (starty == endy) { + adj[m + N].push_back({m + 1 + N, (int)(2LL * std::abs(startx - endx))}); + adj[m + 1 + N].push_back({m, (int)(2LL * std::abs(startx - endx))}); + } + + for (int i = 0; i < m; ++i) { + adj[i].push_back({i + N, 1}); + adj[i + N].push_back({i, 1}); + } + + std::vector dist(prenode, INF); + std::priority_queue, std::greater> pq; + + int startid = m; + int endid = m + 1; + + dist[startid] = 0; + pq.push({0, startid}); + dist[startid + N] = 0; + pq.push({0, startid + N}); + + while (!pq.empty()) { + auto [d, u] = pq.top(); + pq.pop(); + + if (d > dist[u]) { + continue; + } + + for (auto &edge : adj[u]) { + int v = edge.first; + int weight = edge.second; + if (dist[u] + weight < dist[v]) { + dist[v] = dist[u] + weight; + pq.push({dist[v], v}); + } + } + } + + ll result = std::min(dist[endid], dist[endid + N]); + + if (result == INF) { + std::cout << -1 << "\n"; + } else { + std::cout << result << "\n"; + } +} \ No newline at end of file diff --git a/src/10/2/wwfsqf.cpp b/src/10/2/wwfsqf.cpp index 1ac70d9..1cceb6e 100644 --- a/src/10/2/wwfsqf.cpp +++ b/src/10/2/wwfsqf.cpp @@ -1,21 +1,32 @@ #include #include #include +#include #include using ll = int64_t; #define sl static inline - +std::vector> edg; ll T,n; +std::vector> pq; -sl void dfs(ll n){ +sl void merge(ll f,ll s){ } +sl void dfs(ll u){ + for(auto v:edg[u]){ + dfs(v); + + } +} + sl void solve(){ std::cin>>n; - std::vector> edg; + edg.clear(); + pq.clear(); + pq.resize(n+1); edg.resize(n+1); for(ll i=1;i<=n-1;i++){ ll u,v;