제출 #336158

#제출 시각아이디문제언어결과실행 시간메모리
336158duality자매 도시 (APIO20_swap)C++11
100 / 100
312 ms17252 KiB
#define DEBUG 0 #include <bits/stdc++.h> using namespace std; #if DEBUG // basic debugging macros int __i__,__j__; #define printLine(l) for(__i__=0;__i__<l;__i__++){cout<<"-";}cout<<endl #define printLine2(l,c) for(__i__=0;__i__<l;__i__++){cout<<c;}cout<<endl #define printVar(n) cout<<#n<<": "<<n<<endl #define printArr(a,l) cout<<#a<<": ";for(__i__=0;__i__<l;__i__++){cout<<a[__i__]<<" ";}cout<<endl #define print2dArr(a,r,c) cout<<#a<<":\n";for(__i__=0;__i__<r;__i__++){for(__j__=0;__j__<c;__j__++){cout<<a[__i__][__j__]<<" ";}cout<<endl;} #define print2dArr2(a,r,c,l) cout<<#a<<":\n";for(__i__=0;__i__<r;__i__++){for(__j__=0;__j__<c;__j__++){cout<<setw(l)<<setfill(' ')<<a[__i__][__j__]<<" ";}cout<<endl;} // advanced debugging class // debug 1,2,'A',"test"; class _Debug { public: template<typename T> _Debug& operator,(T val) { cout << val << endl; return *this; } }; #define debug _Debug(), #else #define printLine(l) #define printLine2(l,c) #define printVar(n) #define printArr(a,l) #define print2dArr(a,r,c) #define print2dArr2(a,r,c,l) #define debug #endif // define #define MAX_VAL 999999999 #define MAX_VAL_2 999999999999999999LL #define EPS 1e-6 #define mp make_pair #define pb push_back // typedef typedef unsigned int UI; typedef long long int LLI; typedef unsigned long long int ULLI; typedef unsigned short int US; typedef pair<int,int> pii; typedef pair<LLI,LLI> plli; typedef vector<int> vi; typedef vector<LLI> vlli; typedef vector<pii> vpii; typedef vector<plli> vplli; // ---------- END OF TEMPLATE ---------- int m; struct edge { int u,v,w; }; bool comp(edge a,edge b) { return a.w < b.w; } edge edges[200000]; int deg[100000]; int parent[100000],r[100000],parentt[100000],goodt[100000]; int find(int n) { if (parent[n] == n) return n; else return find(parent[n]); } void init(int N,int M,vector<int> U,vector<int> V,vector<int> W) { int i; m = M; for (i = 0; i < M; i++) edges[i] = (edge){U[i],V[i],W[i]}; sort(edges,edges+M,comp); for (i = 0; i < N; i++) parent[i] = i,r[i] = 1,parentt[i] = goodt[i] = M; for (i = 0; i < M; i++) { int u = find(edges[i].u),v = find(edges[i].v); deg[edges[i].u]++,deg[edges[i].v]++; if (u != v) { if (r[u] > r[v]) swap(u,v); parent[u] = v,parentt[u] = i; if (goodt[u] < M) goodt[v] = min(goodt[v],i); if (r[u] == r[v]) r[v]++; } if ((u == v) || (deg[edges[i].u] >= 3) || (deg[edges[i].v] >= 3)) goodt[v] = min(goodt[v],i); } } int getMinimumFuelCapacity(int X,int Y) { int l = 0,r = m; while (l < r) { int mid = (l+r) / 2; int u = X,v = Y; while (parentt[u] <= mid) u = parent[u]; while (parentt[v] <= mid) v = parent[v]; if ((u == v) && (goodt[u] <= mid)) r = mid; else l = mid+1; } return (l == m) ? -1:edges[l].w; }
#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...