/ Vijos /

记录详情

Accepted

foo.cc: In function 'void dfs(int)':
foo.cc:2:610: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<node>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
    2 | using namespace std;typedef long long LL;const int inf=0x3f3f3f3f;const int N=1e4+9;const int M=5e4+9;struct Edge{int u,v,w;}E[M];bool cmp(Edge x,Edge y){return x.w>y.w;}struct node{int v,w;};vector<node>G[N];int n,m,q,f[N][20],d[N],st[N][20];int fa[N],col[N],color=0;inline int get(int x){while(x!=fa[x])x=fa[x]=fa[fa[x]];return x;}inline void kruskal(){for(int i=1;i<=n;i++)fa[i]=i;sort(E+1,E+m+1,cmp);for(int i=1;i<=m;i++){int u=E[i].u,v=E[i].v,w=E[i].w;int fu=get(u),fv=get(v);if(fu!=fv){fa[fv]=fu;G[u].push_back({v,w});G[v].push_back({u,w});}}}void dfs(int u){col[u]=color;d[u]=d[f[u][0]]+1;for(int i=0;i<G[u].size();i++){int v=G[u][i].v;if(v==f[u][0])continue;f[v][0]=u;st[v][0]=G[u][i].w;dfs(v);}}int Log[N];inline void getLog(){for(int i=2;i<=n;i++)Log[i]=Log[i/2]+1;}inline int lca(int x,int y){if(col[x]!=col[y])return-1;if(d[x]<d[y])swap(x,y);int k=Log[d[x]],ans=inf;for(int i=k;i>=0;i--){if(d[f[x][i]]>=d[y]){ans=min(ans,st[x][i]);x=f[x][i];}}if(x==y)return ans;for(int i=k;i>=0;i--){if(f[x][i]!=f[y][i]){ans=min(ans,min(st[x][i],st[y][i]));x=f[x][i];y=f[y][i];}}return min(ans,min(st[x][0],st[y][0]));}int main(){scanf("%d%d",&n,&m);for(int i=1;i<=m;i++){scanf("%d%d%d",&E[i].u,&E[i].v,&E[i].w);}kruskal();for(int i=1;i<=n;i++){if(!col[i]){color++;dfs(i);st[i][0]=inf;}}for(int j=1;(1<<j)<=n;j++){for(int i=1;i<=n;i++){f[i][j]=f[f[i][j-1]][j-1];st[i][j]=min(st[i][j-1],st[f[i][j-1]][j-1]);}}getLog();scanf("%d",&q);while(q--){int x,y;scanf("%d%d",&x,&y);printf("%d\n",lca(x,y));}return 0;}
      |                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                 ~^~~~~~~~~~~~
foo.cc: In function 'int main()':
foo.cc:2:1132: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
    2 | using namespace std;typedef long long LL;const int inf=0x3f3f3f3f;const int N=1e4+9;const int M=5e4+9;struct Edge{int u,v,w;}E[M];bool cmp(Edge x,Edge y){return x.w>y.w;}struct node{int v,w;};vector<node>G[N];int n,m,q,f[N][20],d[N],st[N][20];int fa[N],col[N],color=0;inline int get(int x){while(x!=fa[x])x=fa[x]=fa[fa[x]];return x;}inline void kruskal(){for(int i=1;i<=n;i++)fa[i]=i;sort(E+1,E+m+1,cmp);for(int i=1;i<=m;i++){int u=E[i].u,v=E[i].v,w=E[i].w;int fu=get(u),fv=get(v);if(fu!=fv){fa[fv]=fu;G[u].push_back({v,w});G[v].push_back({u,w});}}}void dfs(int u){col[u]=color;d[u]=d[f[u][0]]+1;for(int i=0;i<G[u].size();i++){int v=G[u][i].v;if(v==f[u][0])continue;f[v][0]=u;st[v][0]=G[u][i].w;dfs(v);}}int Log[N];inline void getLog(){for(int i=2;i<=n;i++)Log[i]=Log[i/2]+1;}inline int lca(int x,int y){if(col[x]!=col[y])return-1;if(d[x]<d[y])swap(x,y);int k=Log[d[x]],ans=inf;for(int i=k;i>=0;i--){if(d[f[x][i]]>=d[y]){ans=min(ans,st[x][i]);x=f[x][i];}}if(x==y)return ans;for(int i=k;i>=0;i--){if(f[x][i]!=f[y][i]){ans=min(ans,min(st[x][i],st[y][i]));x=f[x][i];y=f[y][i];}}return min(ans,min(st[x][0],st[y][0]));}int main(){scanf("%d%d",&n,&m);for(int i=1;i<=m;i++){scanf("%d%d%d",&E[i].u,&E[i].v,&E[i].w);}kruskal();for(int i=1;i<=n;i++){if(!col[i]){color++;dfs(i);st[i][0]=inf;}}for(int j=1;(1<<j)<=n;j++){for(int i=1;i<=n;i++){f[i][j]=f[f[i][j-1]][j-1];st[i][j]=min(st[i][j-1],st[f[i][j-1]][j-1]);}}getLog();scanf("%d",&q);while(q--){int x,y;scanf("%d%d",&x,&y);printf("%d\n",lca(x,y));}return 0;}
      |                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       ~~~~~^~~~~~~~~~~~~~
foo.cc:2:1174: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
    2 | using namespace std;typedef long long LL;const int inf=0x3f3f3f3f;const int N=1e4+9;const int M=5e4+9;struct Edge{int u,v,w;}E[M];bool cmp(Edge x,Edge y){return x.w>y.w;}struct node{int v,w;};vector<node>G[N];int n,m,q,f[N][20],d[N],st[N][20];int fa[N],col[N],color=0;inline int get(int x){while(x!=fa[x])x=fa[x]=fa[fa[x]];return x;}inline void kruskal(){for(int i=1;i<=n;i++)fa[i]=i;sort(E+1,E+m+1,cmp);for(int i=1;i<=m;i++){int u=E[i].u,v=E[i].v,w=E[i].w;int fu=get(u),fv=get(v);if(fu!=fv){fa[fv]=fu;G[u].push_back({v,w});G[v].push_back({u,w});}}}void dfs(int u){col[u]=color;d[u]=d[f[u][0]]+1;for(int i=0;i<G[u].size();i++){int v=G[u][i].v;if(v==f[u][0])continue;f[v][0]=u;st[v][0]=G[u][i].w;dfs(v);}}int Log[N];inline void getLog(){for(int i=2;i<=n;i++)Log[i]=Log[i/2]+1;}inline int lca(int x,int y){if(col[x]!=col[y])return-1;if(d[x]<d[y])swap(x,y);int k=Log[d[x]],ans=inf;for(int i=k;i>=0;i--){if(d[f[x][i]]>=d[y]){ans=min(ans,st[x][i]);x=f[x][i];}}if(x==y)return ans;for(int i=k;i>=0;i--){if(f[x][i]!=f[y][i]){ans=min(ans,min(st[x][i],st[y][i]));x=f[x][i];y=f[y][i];}}return min(ans,min(st[x][0],st[y][0]));}int main(){scanf("%d%d",&n,&m);for(int i=1;i<=m;i++){scanf("%d%d%d",&E[i].u,&E[i].v,&E[i].w);}kruskal();for(int i=1;i<=n;i++){if(!col[i]){color++;dfs(i);st[i][0]=inf;}}for(int j=1;(1<<j)<=n;j++){for(int i=1;i<=n;i++){f[i][j]=f[f[i][j-1]][j-1];st[i][j]=min(st[i][j-1],st[f[i][j-1]][j-1]);}}getLog();scanf("%d",&q);while(q--){int x,y;scanf("%d%d",&x,&y);printf("%d\n",lca(x,y));}return 0;}
      |                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                 ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
foo.cc:2:1419: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
    2 | using namespace std;typedef long long LL;const int inf=0x3f3f3f3f;const int N=1e4+9;const int M=5e4+9;struct Edge{int u,v,w;}E[M];bool cmp(Edge x,Edge y){return x.w>y.w;}struct node{int v,w;};vector<node>G[N];int n,m,q,f[N][20],d[N],st[N][20];int fa[N],col[N],color=0;inline int get(int x){while(x!=fa[x])x=fa[x]=fa[fa[x]];return x;}inline void kruskal(){for(int i=1;i<=n;i++)fa[i]=i;sort(E+1,E+m+1,cmp);for(int i=1;i<=m;i++){int u=E[i].u,v=E[i].v,w=E[i].w;int fu=get(u),fv=get(v);if(fu!=fv){fa[fv]=fu;G[u].push_back({v,w});G[v].push_back({u,w});}}}void dfs(int u){col[u]=color;d[u]=d[f[u][0]]+1;for(int i=0;i<G[u].size();i++){int v=G[u][i].v;if(v==f[u][0])continue;f[v][0]=u;st[v][0]=G[u][i].w;dfs(v);}}int Log[N];inline void getLog(){for(int i=2;i<=n;i++)Log[i]=Log[i/2]+1;}inline int lca(int x,int y){if(col[x]!=col[y])return-1;if(d[x]<d[y])swap(x,y);int k=Log[d[x]],ans=inf;for(int i=k;i>=0;i--){if(d[f[x][i]]>=d[y]){ans=min(ans,st[x][i]);x=f[x][i];}}if(x==y)return ans;for(int i=k;i>=0;i--){if(f[x][i]!=f[y][i]){ans=min(ans,min(st[x][i],st[y][i]));x=f[x][i];y=f[y][i];}}return min(ans,min(st[x][0],st[y][0]));}int main(){scanf("%d%d",&n,&m);for(int i=1;i<=m;i++){scanf("%d%d%d",&E[i].u,&E[i].v,&E[i].w);}kruskal();for(int i=1;i<=n;i++){if(!col[i]){color++;dfs(i);st[i][0]=inf;}}for(int j=1;(1<<j)<=n;j++){for(int i=1;i<=n;i++){f[i][j]=f[f[i][j-1]][j-1];st[i][j]=min(st[i][j-1],st[f[i][j-1]][j-1]);}}getLog();scanf("%d",&q);while(q--){int x,y;scanf("%d%d",&x,&y);printf("%d\n",lca(x,y));}return 0;}
      |                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                      ~~~~~^~~~~~~~~
foo.cc:2:1453: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
    2 | using namespace std;typedef long long LL;const int inf=0x3f3f3f3f;const int N=1e4+9;const int M=5e4+9;struct Edge{int u,v,w;}E[M];bool cmp(Edge x,Edge y){return x.w>y.w;}struct node{int v,w;};vector<node>G[N];int n,m,q,f[N][20],d[N],st[N][20];int fa[N],col[N],color=0;inline int get(int x){while(x!=fa[x])x=fa[x]=fa[fa[x]];return x;}inline void kruskal(){for(int i=1;i<=n;i++)fa[i]=i;sort(E+1,E+m+1,cmp);for(int i=1;i<=m;i++){int u=E[i].u,v=E[i].v,w=E[i].w;int fu=get(u),fv=get(v);if(fu!=fv){fa[fv]=fu;G[u].push_back({v,w});G[v].push_back({u,w});}}}void dfs(int u){col[u]=color;d[u]=d[f[u][0]]+1;for(int i=0;i<G[u].size();i++){int v=G[u][i].v;if(v==f[u][0])continue;f[v][0]=u;st[v][0]=G[u][i].w;dfs(v);}}int Log[N];inline void getLog(){for(int i=2;i<=n;i++)Log[i]=Log[i/2]+1;}inline int lca(int x,int y){if(col[x]!=col[y])return-1;if(d[x]<d[y])swap(x,y);int k=Log[d[x]],ans=inf;for(int i=k;i>=0;i--){if(d[f[x][i]]>=d[y]){ans=min(ans,st[x][i]);x=f[x][i];}}if(x==y)return ans;for(int i=k;i>=0;i--){if(f[x][i]!=f[y][i]){ans=min(ans,min(st[x][i],st[y][i]));x=f[x][i];y=f[y][i];}}return min(ans,min(st[x][0],st[y][0]));}int main(){scanf("%d%d",&n,&m);for(int i=1;i<=m;i++){scanf("%d%d%d",&E[i].u,&E[i].v,&E[i].w);}kruskal();for(int i=1;i<=n;i++){if(!col[i]){color++;dfs(i);st[i][0]=inf;}}for(int j=1;(1<<j)<=n;j++){for(int i=1;i<=n;i++){f[i][j]=f[f[i][j-1]][j-1];st[i][j]=min(st[i][j-1],st[f[i][j-1]][j-1]);}}getLog();scanf("%d",&q);while(q--){int x,y;scanf("%d%d",&x,&y);printf("%d\n",lca(x,y));}return 0;}
      |                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                        ~~~~~^~~~~~~~~~~~~~
[Hydro](https://hydro.ac)提供评测服务
# 状态 耗时 内存占用
#1 Accepted 3ms 640.0 KiB
#2 Accepted 3ms 640.0 KiB
#3 Accepted 5ms 896.0 KiB
#4 Accepted 5ms 896.0 KiB
#5 Accepted 16ms 1016.0 KiB
#6 Accepted 6ms 896.0 KiB
#7 Accepted 24ms 1.992 MiB
#8 Accepted 20ms 1.867 MiB
#9 Accepted 22ms 1.992 MiB
#10 Accepted 21ms 1.867 MiB
#11 Accepted 30ms 1.992 MiB
#12 Accepted 22ms 1.992 MiB
#13 Accepted 44ms 4.367 MiB
#14 Accepted 60ms 3.871 MiB
#15 Accepted 49ms 3.992 MiB
#16 Accepted 45ms 3.965 MiB
#17 Accepted 46ms 4.242 MiB
#18 Accepted 68ms 3.867 MiB
#19 Accepted 54ms 3.742 MiB
#20 Accepted 62ms 3.742 MiB

信息

递交者
类型
递交
题目
P1843 货车运输
语言
C++
递交时间
2022-02-18 22:31:52
评测时间
2022-02-18 23:00:03
评测机
分数
100
总耗时
614ms
峰值内存
4.367 MiB