結果
| 問題 | No.114 遠い未来 |
| コンテスト | |
| ユーザー |
👑 kmjp
|
| 提出日時 | 2014-12-28 23:39:31 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0 + boost 1.89.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,873 bytes |
| 記録 | |
| コンパイル時間 | 1,566 ms |
| コンパイル使用メモリ | 167,580 KB |
| 実行使用メモリ | 6,948 KB |
| 最終ジャッジ日時 | 2024-06-12 23:56:44 |
| 合計ジャッジ時間 | 2,026 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 WA * 1 |
| other | AC * 12 WA * 13 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
typedef signed long long ll;
#undef _P
#define _P(...) (void)printf(__VA_ARGS__)
#define FOR(x,to) for(x=0;x<to;x++)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
//-------------------------------------------------------
class UF {
public:
static const int ufmax=5052;
int ufpar[ufmax],ufrank[ufmax],ufcnt[ufmax];
UF() { int i; FOR(i,ufmax) { ufpar[i]=i; ufrank[i]=0; ufcnt[i]=1; } }
int operator[](int x) {return (ufpar[x]==x)?(x):(ufpar[x] = operator[](ufpar[x]));}
int count(int x) { return ufcnt[operator[](x)];}
void unite(int x,int y) {
x = operator[](x); y = operator[](y);
if(x==y) return;
if(ufrank[x]<ufrank[y]) ufpar[x]=y, ufcnt[y]+=ufcnt[x];
else {ufpar[y]=x; ufcnt[x]+=ufcnt[y]; if(ufrank[x]==ufrank[y]) ufrank[x]++;}
}
};
int N,M,T;
int A[2000],B[2000],C[2000];
int V[2000];
int mat[40][40];
int ok[40];
void solve() {
int i,j,k,l,r,x,y; string s;
UF uf;
FOR(x,40) FOR(y,40) mat[x][y]=100000000;
FOR(x,40) mat[x][x]=0;
cin>>N>>M>>T;
FOR(i,M) {
cin>>A[i]>>B[i]>>C[i];
mat[A[i]-1][B[i]-1]=mat[B[i]-1][A[i]-1]=C[i];
}
FOR(i,N) FOR(x,N) FOR(y,N) mat[x][y]=min(mat[x][y],mat[x][i]+mat[i][y]);
FOR(i,T) cin>>V[i], V[i]--, ok[V[i]]=1;
priority_queue<pair<int,int> > Q;
FOR(x,N) FOR(y,N) if(x!=y && ok[x]&&ok[y]) Q.push(make_pair(-mat[x][y],x*100+y));
int tot=0;
while(Q.size()) {
pair<int,int> p=Q.top();
Q.pop();
x=p.second/100, y=p.second%100;
if(uf[x]!=uf[y]) {
tot+=-p.first;
uf.unite(x,y);
}
}
cout<<tot<<endl;
}
int main(int argc,char** argv){
string s;int i;
if(argc==1) ios::sync_with_stdio(false);
FOR(i,argc-1) s+=argv[i+1],s+='\n';
FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin);
solve(); return 0;
}
kmjp