제출 #996467

#제출 시각아이디문제언어결과실행 시간메모리
996467Dan4Life자매 도시 (APIO20_swap)C++17
37 / 100
2074 ms13856 KiB
#include "swap.h" #include <bits/stdc++.h> using namespace std; #define all(a) begin(a),end(a) #define sz(a) (int)a.size() #define pb push_back const int mxN = (int)3e5+10; int n, m, deg[mxN]; int p[mxN], cycle[mxN], line[mxN]; vector<array<int,3>> edges; void init(int N, int M, vector<int> U, vector<int> V, vector<int> W) { n = N, m = M; for(int i = 0; i < M; i++) edges.pb({W[i],U[i],V[i]}); sort(all(edges),[&](array<int,3> a, array<int,3> b){ return a[0]<b[0]; }); } int findSet(int i){return p[i]==i?i:p[i]=findSet(p[i]);} bool isSameSet(int i, int j) { return findSet(i)==findSet(j); } void unionSet(int i, int j){ deg[i]++, deg[j]++; int x = findSet(i), y = findSet(j); if(x==y){ cycle[x] = true; return; } if(!line[x] or !line[y] or deg[i]>=3 or deg[j]>=3) line[x]=line[y]=0; p[y] = x; } bool check(int x, int s, int t){ for(int i = 0; i < n; i++) p[i]=i,cycle[i]=0,deg[i]=0,line[i]=1; for(int i = 0; i <= x; i++) unionSet(edges[i][1],edges[i][2]); if(!isSameSet(s,t)) return false; int set = findSet(s); return cycle[set] or !line[set]; } int getMinimumFuelCapacity(int X, int Y) { int l = 0, r = m-1; if(!check(r,X,Y)) return -1; while(l<r){ int mid = (l+r)/2; if(check(mid,X,Y)) r=mid; else l=mid+1; } return edges[l][0]; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...