2000万优秀解决方案库,覆盖所有编程及软件开发类,极速查询
今日已更新 1576 篇代码解决方案
2024-09-11 21:52:25 216人阅读
6 21 2 12 4 12 5 15 6 11 3 12 64 5
12
1 #include<iostream> 2 #include<cstdio> 3 #include<cstdlib> 4 #include<cstring> 5 #include<algorithm> 6 using namespace std; 7 const int N=10050; 8 typedef long long ll; 9 10 11 struct Edge{12 int to,next;13 ll val;14 }edge[N];15 int n,m,x,y,first[N],tot;16 int S[N],E[N],Tim;17 ll sum,dis[N],z;18 19 template <class T>20 inline void read(T &s){21 int flag=1;s=0;char ch=getchar();22 while(ch<‘0‘ || ch>‘9‘){if(ch==‘-‘)flag=-1;ch=getchar();}23 while(ch>=‘0‘ && ch<=‘9‘){s=s*10+ch-‘0‘;ch=getchar();}24 s*=flag;25 }26 void dfs(int x){27 S[x]=++Tim;28 for(int i=first[x];i;i=edge[i].next){29 dis[edge[i].to]=dis[x]+edge[i].val;30 dfs(edge[i].to);31 }32 E[x]=++Tim;33 }34 inline void Add_edge(int a,int b,int c){35 edge[++tot].to=b;edge[tot].val=c;edge[tot].next=first[a];first[a]=tot;36 }37 int main(){38 read(n);read(m);39 for(int i=1;i<n;++i){40 read(x);read(y);read(z);41 Add_edge(x,y,z);42 }43 dfs(1);44 int ans=0;45 for(int i=1;i<=m;++i){46 read(x);read(y);47 if(S[x]<S[y] && E[x]>E[y]){48 ++ans;sum+=dis[y]-dis[x];49 }50 }51 printf("%d\n%lld\n",ans,sum);52 return 0;53 }
【jzoj1209】【vijos1460】拉力赛
https://www.u72.net/daima/8wss.html
联系 我们
回到 顶部