제출 #630444

#제출 시각아이디문제언어결과실행 시간메모리
630444colazcyCeste (COCI17_ceste)C++17
160 / 160
178 ms596 KiB
#include <cstdio> #include <cassert> #include <vector> #include <queue> #define let const auto #define rep(name,beg,end) for(auto lim_##name = end,name = beg;name <= lim_##name;name++) #define per(name,beg,end) for(auto lim_##name = end,name = beg;name >= lim_##name;name--) #define repn(lim) for(auto REPN_lIM = lim,REPN = 1;REPN <= REPN_lIM;REPN++) #define debug(...) fprintf(stderr,__VA_ARGS__) #define trace() debug("line : %d, Function : %s\n",__LINE__,__FUNCTION__) using ll = long long; using type = double; constexpr int maxn = 2e3 + 100; constexpr ll inf = 0x3f3f3f3f3f3f3f3f; struct Vector{ int x,y; Vector operator + (const Vector t)const{return Vector{x + t.x,y + t.y};} }; int n,m; type dis[maxn]; Vector vec[maxn]; std::vector<std::pair<int,Vector>> G[maxn]; struct Node{ int u; type h; bool operator < (const Node t)const{ return h > t.h; } }; ll ans[maxn]; void dij(const type t){ // t * x + (1 - t) * y static bool vis[maxn]; static std::priority_queue<Node> q; std::fill_n(dis + 1,n,1e9); std::fill_n(vec + 1,n,Vector{0x7fffffff,0x7fffffff}); std::fill_n(vis + 1,n,false); vec[1] = Vector{0,0}; dis[1] = 0; q.push(Node{1,0}); while(!q.empty()){ let u = q.top().u; q.pop(); if(vis[u])continue; vis[u] = 1; for(let &pir : G[u]){ let v = pir.first; let w = pir.second; let m = t * w.x + (1 - t) * w.y; if(dis[u] + m < dis[v]){ dis[v] = dis[u] + m; vec[v] = vec[u] + w; q.push(Node{v,dis[v]}); } } } rep(i,2,n)ans[i] = std::min(ans[i],1ll * vec[i].x * vec[i].y); } int main(){ std::scanf("%d %d",&n,&m); std::fill_n(ans + 1,n,inf); repn(m){ int u,v,t,c; std::scanf("%d %d %d %d",&u,&v,&t,&c); G[u].emplace_back(v,Vector{t,c}); G[v].emplace_back(u,Vector{t,c}); } type x = 0; while(x <= 1.0){ dij(x); type nxt = 1e9; rep(u,1,n) for(let &pir : G[u]){ let v = pir.first; let w = pir.second; let p = (-vec[u].y + vec[v].y - w.y); let q = (vec[u].x - vec[u].y + w.x - w.y - vec[v].x + vec[v].y); let s = type(p) / q; if(s > x)nxt = std::min(nxt,s); } x = nxt; } rep(i,2,n)std::printf("%lld\n",ans[i] >= inf ? -1 : ans[i]); return 0; }

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

ceste.cpp: In function 'int main()':
ceste.cpp:58:15: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   58 |     std::scanf("%d %d",&n,&m);
      |     ~~~~~~~~~~^~~~~~~~~~~~~~~
ceste.cpp:61:32: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   61 |         int u,v,t,c; std::scanf("%d %d %d %d",&u,&v,&t,&c);
      |                      ~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~
#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...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...