結果
問題 | No.2630 Colorful Vertices and Cheapest Paths |
ユーザー | maksim |
提出日時 | 2024-02-16 23:17:35 |
言語 | C++14 (gcc 12.3.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 288 ms / 2,500 ms |
コード長 | 1,422 bytes |
コンパイル時間 | 1,872 ms |
コンパイル使用メモリ | 173,408 KB |
実行使用メモリ | 6,548 KB |
最終ジャッジ日時 | 2024-02-16 23:18:22 |
合計ジャッジ時間 | 7,249 ms |
ジャッジサーバーID (参考情報) |
judge15 / judge14 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 132 ms
6,548 KB |
testcase_01 | AC | 283 ms
6,548 KB |
testcase_02 | AC | 258 ms
6,548 KB |
testcase_03 | AC | 35 ms
6,548 KB |
testcase_04 | AC | 35 ms
6,548 KB |
testcase_05 | AC | 34 ms
6,548 KB |
testcase_06 | AC | 136 ms
6,548 KB |
testcase_07 | AC | 217 ms
6,548 KB |
testcase_08 | AC | 210 ms
6,548 KB |
testcase_09 | AC | 217 ms
6,548 KB |
testcase_10 | AC | 287 ms
6,548 KB |
testcase_11 | AC | 286 ms
6,548 KB |
testcase_12 | AC | 288 ms
6,548 KB |
testcase_13 | AC | 288 ms
6,548 KB |
testcase_14 | AC | 287 ms
6,548 KB |
testcase_15 | AC | 250 ms
6,548 KB |
testcase_16 | AC | 243 ms
6,548 KB |
testcase_17 | AC | 240 ms
6,548 KB |
testcase_18 | AC | 139 ms
6,548 KB |
testcase_19 | AC | 194 ms
6,548 KB |
testcase_20 | AC | 181 ms
6,548 KB |
testcase_21 | AC | 222 ms
6,548 KB |
コンパイルメッセージ
main.cpp: In function 'int32_t main()': main.cpp:43:18: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17' [-Wc++17-extensions] 43 | for(auto [x,y]:b) {if(mask & (1<<c[x])) if(mask & (1<<c[y])) merg(x,y);} | ^ main.cpp:44:43: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17' [-Wc++17-extensions] 44 | for(int j=0;j<v.size();++j) {auto [x,y]=v[j];if(get(x)==get(y)) res[j]=min(res[j],c1);} | ^
ソースコード
#include <bits/stdc++.h> using namespace std; #define int long long #define app push_back #define all(x) (x).begin(),(x).end() #ifdef LOCAL #define debug(...) [](auto...a){ ((cout << a << ' '), ...) << endl;}(#__VA_ARGS__, ":", __VA_ARGS__) #else #define debug(...) #endif #ifdef LOCAL #define __int128 long long #endif // LOCAL const int inf=1e18; const int maxn=1e5+5; int c[maxn];int w[10]; int res[maxn]; int par[maxn]; int get(int x) { if(par[x]==(-1)) return x; int ans=get(par[x]);par[x]=ans;return ans; } void merg(int x,int y) { x=get(x);y=get(y);if(x!=y) par[x]=y; } int32_t main() { ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0); int n,m;cin>>n>>m; vector<pair<int,int> > b; for(int i=0;i<m;++i) {int x,y;cin>>x>>y;--x;--y;b.app({x,y});} for(int i=0;i<n;++i) {cin>>c[i];--c[i];} for(int i=0;i<10;++i) cin>>w[i]; int q;cin>>q;vector<pair<int,int> > v; for(int cyc=0;cyc<q;++cyc) {int x,y;cin>>x>>y;--x;--y;v.app({x,y});} fill(res,res+q,inf); for(int mask=0;mask<(1<<10);++mask) { fill(par,par+maxn,-1);int c1=0; for(int i=0;i<10;++i) {if(mask & (1<<i)) {c1+=w[i];}} for(auto [x,y]:b) {if(mask & (1<<c[x])) if(mask & (1<<c[y])) merg(x,y);} for(int j=0;j<v.size();++j) {auto [x,y]=v[j];if(get(x)==get(y)) res[j]=min(res[j],c1);} } for(int i=0;i<q;++i) {cout<<(res[i]==inf ? -1 : res[i])<<'\n';} return 0; }