結果
問題 | No.2642 Don't cut line! |
ユーザー | GOTKAKO |
提出日時 | 2024-02-20 11:02:24 |
言語 | C++17 (gcc 12.3.0 + boost 1.83.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 3,449 bytes |
コンパイル時間 | 2,724 ms |
コンパイル使用メモリ | 232,476 KB |
実行使用メモリ | 31,988 KB |
最終ジャッジ日時 | 2024-09-29 03:28:50 |
合計ジャッジ時間 | 7,996 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge5 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 2 ms
6,820 KB |
testcase_01 | AC | 127 ms
29,808 KB |
testcase_02 | AC | 125 ms
31,988 KB |
testcase_03 | AC | 131 ms
31,088 KB |
testcase_04 | AC | 133 ms
30,712 KB |
testcase_05 | AC | 132 ms
29,688 KB |
testcase_06 | AC | 43 ms
6,820 KB |
testcase_07 | WA | - |
testcase_08 | WA | - |
testcase_09 | AC | 42 ms
6,820 KB |
testcase_10 | AC | 45 ms
6,820 KB |
testcase_11 | AC | 44 ms
6,816 KB |
testcase_12 | WA | - |
testcase_13 | AC | 44 ms
6,816 KB |
testcase_14 | WA | - |
testcase_15 | AC | 44 ms
6,816 KB |
testcase_16 | RE | - |
testcase_17 | RE | - |
testcase_18 | RE | - |
testcase_19 | RE | - |
testcase_20 | AC | 48 ms
10,368 KB |
testcase_21 | AC | 43 ms
6,816 KB |
testcase_22 | RE | - |
testcase_23 | RE | - |
testcase_24 | AC | 50 ms
13,184 KB |
testcase_25 | AC | 48 ms
12,032 KB |
testcase_26 | AC | 46 ms
7,040 KB |
testcase_27 | RE | - |
testcase_28 | RE | - |
testcase_29 | AC | 47 ms
8,320 KB |
testcase_30 | AC | 47 ms
10,880 KB |
testcase_31 | RE | - |
testcase_32 | AC | 48 ms
9,856 KB |
testcase_33 | AC | 2 ms
6,816 KB |
testcase_34 | AC | 2 ms
6,820 KB |
testcase_35 | AC | 2 ms
6,816 KB |
コンパイルメッセージ
main.cpp: In member function 'int LowestCommonAncestor::twodist2(int, int)': main.cpp:89:5: warning: no return statement in function returning non-void [-Wreturn-type] 89 | } | ^
ソースコード
#include <bits/stdc++.h> using namespace std; class UnionFind{ public: vector<int> par,siz; void make(int N){ par.resize(N,-1); siz.resize(N,1); } int root(int x){ if(par.at(x) == -1) return x; else return par.at(x) = root(par.at(x)); } void unite(int u, int v){ u = root(u),v = root(v); if(u == v) return; if(siz.at(u) < siz.at(v)) swap(u,v); par.at(v) = u; siz.at(u) += siz.at(v); } bool issame(int u, int v){ if(root(u) == root(v)) return true; else return false; } }; class LowestCommonAncestor{ public: vector<vector<int>> par,maxd; vector<int> dist; void make(vector<vector<pair<int,int>>> &Graph,int root){ int N = Graph.size(),K = 1; while((1<<K) < N) K++; par.resize(K,vector<int>(N,-1)); maxd.resize(K,vector<int>(N)); dist.resize(N,-1); dfs(Graph,root,-1,0); for(int i=1; i<K; i++){ for(int k=0; k<N; k++){ if(par.at(i-1).at(k) == -1) par.at(i).at(k) = -1,maxd.at(i).at(k) = maxd.at(i-1).at(k); else{ par.at(i).at(k) = par.at(i-1).at(par.at(i-1).at(k)); maxd.at(i).at(k) = max(maxd.at(i-1).at(k),maxd.at(i-1).at(par.at(i-1).at(k))); } } } }; void dfs(vector<vector<pair<int,int>>> &Graph,int pos,int back,int d){ dist.at(pos) = d; par.at(0).at(pos) = back; for(auto [to,w] : Graph.at(pos)){ if(to == back) continue; maxd.at(0).at(to) = w; dfs(Graph,to,pos,d+1); } } int LCA(int u,int v){ int costu = 0,costv = 0; if(dist.at(u) < dist.at(v)) swap(u,v); int K = par.size(),diff = dist.at(u)-dist.at(v); for(int i=0; i<K; i++){ if(!(diff&(1<<i))) continue; u = par.at(i).at(u); costu = max(costu,maxd.at(i).at(u)); diff -= 1<<i; } if(u == v) return max(costu,costv); for(int i=K-1; i>=0; i--){ if(par.at(i).at(u) == par.at(i).at(v)) continue; u = par.at(i).at(u),v = par.at(i).at(v); costu = max(costu,maxd.at(i).at(u)),costv = max(costv,maxd.at(i).at(v)); } return max(costu,costv); } int twodist(int u,int v){ int lca = LCA(u,v); return dist.at(u)+dist.at(v)-2*dist.at(lca); } int twodist2(int u,int v){ } }; int main() { ios_base::sync_with_stdio(false); cin.tie(nullptr); long long N,K,C; cin >> N >> K >> C; vector<tuple<int,int,int,int>> WPUV(K); for(auto &[w,p,u,v] : WPUV) cin >> u >> v >> w >> p,u--,v--; sort(WPUV.begin(),WPUV.end()); int answer = 0; long long cost = 0; UnionFind UF; UF.make(N); vector<vector<pair<int,int>>> Graph(N); for(int i=0; i<N; i++){ auto[w,p,u,v] = WPUV.at(i); if(UF.issame(u,v)) continue; UF.unite(u,v); cost += w; answer = max(answer,p); Graph.at(u).push_back({v,w}); Graph.at(v).push_back({u,w}); } if(cost > C){cout << -1 << endl; return 0;} LowestCommonAncestor Z; Z.make(Graph,0); for(int i=0; i<N; i++){ auto[w,p,u,v] = WPUV.at(i); if(p <= answer) continue; int maxw = Z.LCA(u,v); if(cost+w-maxw <= C) answer = p; } cout << answer << endl; }