제출 #253570

#제출 시각아이디문제언어결과실행 시간메모리
253570blacktulipPutovanje (COCI20_putovanje)C++17
0 / 110
186 ms35320 KiB
#include <bits/stdc++.h> using namespace std; typedef long long lo; typedef pair< lo,lo > PII; #define fi first #define se second #define mp make_pair #define endl "\n" #define pb push_back #define fio() ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL) #define FOR for(int i=1;i<=n;i++) #define mid ((start+end)/2) #define ort ((bas+son)/2) const lo inf = 1000000000000000000; const lo KOK = 100000; const lo LOG = 30; const lo li = 500005; const lo mod = 1000000007; int n,m,b[li],a[li],k,flag,t,c1[li],c2[li],fa[li][LOG],dep[li],vis[li],vis1[li]; int cev; string s; vector<PII> v[li]; inline void build_lca(){ for(int j=1;j<=27;j++){ FOR fa[i][j]=fa[fa[i][j-1]][j-1]; } } inline void ask_lca(int x,int y){ if(dep[x]<dep[y])swap(x,y); int fark=dep[x]-dep[y]; for(int i=27;i>=0;i--){ if((1<<i)<=fark && fa[x][i]!=y){ fark-=(1<<i); x=fa[x][i]; } } if(fa[x][0]==y){vis[x]++;flag=y;return;} for(int i=27;i>=0;i--){ if(fa[x][i]==fa[y][i])continue; x=fa[x][i]; y=fa[y][i]; } vis[x]++; vis[y]++; return ; } inline void dfs(int node,int ata,int der){ dep[node]=der; fa[node][0]=ata; for(int i=0;i<(int)v[node].size();i++){ int go=v[node][i].fi; if(go==ata)continue; dfs(go,node,der+1); } } inline void solve(int node,int ata,int der){ for(int i=0;i<(int)v[node].size();i++){ int go=v[node][i].fi; int ind=v[node][i].se; if(go==ata)continue; int sum=der; sum+=vis[go]; sum+=vis1[node]; a[ind]=sum; solve(go,node,sum); } } int main(void){ scanf("%d",&n); for(int i=1;i<n;i++){ int x,y; scanf("%d %d %d %d",&x,&y,&c1[i],&c2[i]); v[x].pb({y,i}); v[y].pb({x,i}); //~ cout<<x<<": : : "<<y<<endl; } dfs(1,0,0); build_lca(); for(int i=1;i<n;i++){ int x=i; int y=i+1; flag=-1; ask_lca(x,y); if(flag!=x)vis1[x]--; if(flag!=y)vis1[y]--; } //~ FOR{ //~ printf("%d %d\n",vis[i],vis1[i]); //~ } solve(1,0,0); int ans=0; for(int i=1;i<n;i++){ ans+=min(c1[i]*a[i],c2[i]); //~ cout<<a[i]<<endl; } printf("%d\n",ans); return 0; }

컴파일 시 표준 에러 (stderr) 메시지

putovanje.cpp: In function 'int main()':
putovanje.cpp:79:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d",&n);
  ~~~~~^~~~~~~~~
putovanje.cpp:82:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d %d %d %d",&x,&y,&c1[i],&c2[i]);
   ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...