# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
996995 |
2024-06-11T14:48:47 Z |
modwwe |
Cities (BOI16_cities) |
C++17 |
|
86 ms |
15392 KB |
#include<bits/stdc++.h>
#define int long long
//#define ll long long
#define down cout<<'\n';
#define NHP ios_base::sync_with_stdio(0);cout.tie(0);cin.tie(0);
#define modwwe int t;cin>>t; while(t--)
#define bit(i,j) (i>>j&1)
#define sobit(a) __builtin_popcountll(a)
#define task "test"
#define fin(x) freopen(x".inp","r",stdin)
#define fou(x) freopen(x".out","w",stdout)
#define pb push_back
#define checktime cerr << (double)clock() / CLOCKS_PER_SEC * 1000 << " ms";
using namespace std;
const int inf=1e9;
void phongbeo();
const int mod2=1e9+7;
const int mod1=998244353;
struct icd
{
int a,b;
};
struct ib
{
int a;
int b;
};
struct ic
{
int a,b,c;
};
struct id
{
int a,b,c,d;
};
struct ie
{
int a,b,c, d,e,f;
};
int n,m,s1,s2,s4,s3,sf,k,r,mid,s5,s6,mx,s7,s8,s9,mx2,res,dem2=0,dem=0,l;
int i,s10,s12;
int el=29;
main()
{
#ifndef ONLINE_JUDGE
//fin(task),fou(task);
#endif
NHP
/// cin>>s1;
// modwwe
phongbeo(),down
checktime
}
struct cmp
{
bool operator()(ib a,ib b)
{
return a.a>b.a;
}
};
ib dsu[100001];
void reset(int x)
{
dsu[x]={1,x};
}
int get(int x)
{
if(dsu[x].b!=x) dsu[x].b=get(dsu[x].b);
return dsu[x].b;
}
void noi(int x,int y)
{
if(dsu[x].a<dsu[y].a)swap(x,y);
dsu[x].a+=dsu[y].a;
dsu[y].b=x;
}
vector<ic> v;
bool a[100001];
vector<ib> v2[100001];
bool cmp (ic a,ic b)
{
return a.c<b.c;
}
void dfs(int x,int y)
{
for(auto f:v2[x])
{ if(f.a!=y){
dfs(f.a,x);
a[x]=(a[x]|a[f.a]);
if(a[f.a]){
s5+=f.b;
}
}
}
}
void phongbeo()
{
cin>>n>>k>>m;
s2=0;
for(int i=1;i<=n;i++)
reset(i);
for(int i=0; i<k; i++)
cin>>l,a[l]=1;
s4=l;
for(int i=1;i<=m;i++)
{
cin>>l>>r>>s2;
v.pb({l,r,s2});
}
sort(v.begin(),v.end(),cmp);
for(auto x:v)
{
s2=get(x.a);
s3=get(x.b);
if(s2!=s3)
{
noi(s2,s3);
v2[x.a].pb({x.b,x.c});
v2[x.b].pb({x.a,x.c});
}
}
dfs(s4,0);
cout<<s5;
}
Compilation message
cities.cpp:44:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
44 | main()
| ^~~~
cities.cpp: In function 'void phongbeo()':
cities.cpp:101:1: warning: this 'for' clause does not guard... [-Wmisleading-indentation]
101 | for(int i=1;i<=n;i++)
| ^~~
cities.cpp:103:5: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'for'
103 | for(int i=0; i<k; i++)
| ^~~
cities.cpp:103:5: warning: this 'for' clause does not guard... [-Wmisleading-indentation]
cities.cpp:105:9: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'for'
105 | s4=l;
| ^~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
2652 KB |
Output is correct |
2 |
Correct |
1 ms |
2652 KB |
Output is correct |
3 |
Incorrect |
1 ms |
2652 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
81 ms |
14064 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
2 ms |
2904 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
82 ms |
15392 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
86 ms |
14516 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |