제출 #724482

#제출 시각아이디문제언어결과실행 시간메모리
724482Dan4Life꿈 (IOI13_dreaming)C++17
47 / 100
1074 ms16088 KiB
#include "dreaming.h" #include <bits/stdc++.h> using namespace std; #define fi first #define se second #define pb push_back #define sz(a) (int)a.size() #define all(a) a.begin(),a.end() const int mxN = (int)1e5+10; const int INF = (int)1e9; int n, m, l,CC=1,ans2; vector<int> path, v; int vis[mxN], dis[mxN]; vector<pair<int,int>> adj[mxN]; bool dfs2(int s, int p, int t){ if(s==t) return 1; for(auto x : adj[s]){ int u = x.fi, w = x.se; if(u==p) continue; if(dfs2(u,s,t)){ path.pb(w); return 1; } } return 0; } void dfs(int s, int p){ vis[s]=CC; for(auto x : adj[s]){ int u = x.fi, w = x.se; if(u==p) continue; dis[u] = dis[s]+w; dfs(u,s); } } void calcDiam(int s){ int a, b, mx = 0; dis[s]=0; dfs(s,-1); for(int i = 1; i <= n; i++) if(vis[i]==CC and mx<=dis[i]) mx=dis[i],a=i; dis[a]=0; mx = 0; dfs(a,-1); for(int i = 1; i <= n; i++) if(vis[i]==CC and mx<=dis[i]) mx=dis[i],b=i; path.clear(); dfs2(a,-1,b); int dis1 = accumulate(all(path),0), dis2 = 0; int ans = dis1; ans2 = max(ans2, dis1); for(auto u : path){ dis1-=u, dis2+=u; ans = min(ans, max(dis1,dis2)); } v.pb(ans); if(sz(v)==4){ for(int i = sz(v)-2; i>=0; i--) if(v[i]<v[i+1])swap(v[i],v[i+1]); v.pop_back(); } } int travelTime(int N, int M, int L, int a[], int b[], int c[]) { n = N; m = M; l = L; for(int i = 0; i < m; i++){ a[i]++, b[i]++; adj[a[i]].pb({b[i],c[i]}); adj[b[i]].pb({a[i],c[i]}); } for(int i = 1; i <= n; i++) if(!vis[i]) calcDiam(i),CC++; int ans = INF; if(sz(v)==1) return ans2; if(sz(v)>=2) ans = v[sz(v)-1]+l+v[sz(v)-2]; if(sz(v)>=3) ans = max(ans,v[sz(v)-2]+l*2+v[sz(v)-3]); return max(ans, ans2); }

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

dreaming.cpp: In function 'void calcDiam(int)':
dreaming.cpp:43:23: warning: 'b' may be used uninitialized in this function [-Wmaybe-uninitialized]
   43 |     path.clear(); dfs2(a,-1,b);
      |                   ~~~~^~~~~~~~
dreaming.cpp:43:23: warning: 'a' may be used uninitialized in this function [-Wmaybe-uninitialized]
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...