結果
問題 | No.2630 Colorful Vertices and Cheapest Paths |
ユーザー |
|
提出日時 | 2024-02-16 23:17:35 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 271 ms / 2,500 ms |
コード長 | 1,422 bytes |
コンパイル時間 | 1,676 ms |
コンパイル使用メモリ | 173,968 KB |
実行使用メモリ | 6,820 KB |
最終ジャッジ日時 | 2024-09-28 21:59:22 |
合計ジャッジ時間 | 6,698 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 22 |
コンパイルメッセージ
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 // LOCALconst 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;}