제출 #944287

#제출 시각아이디문제언어결과실행 시간메모리
944287vjudge1Dynamic Diameter (CEOI19_diameter)C++17
11 / 100
5041 ms24216 KiB
#include <bits/stdc++.h> using namespace std; #define int long long #define pb push_back #define ff first #define ss second #define all(v) v.begin(), v.end() #define rall(v) v.rbegin(), v.rend() #define sz(v) (int)v.size() const int INF = 1e18; const int mod = 998244353; const int N = 1e5+5; vector<int> g[N]; map<pair<int,int>,int> w; void solve(){ int n, qr, maxw; cin >> n >> qr >> maxw; vector<pair<int,int> > edges; for(int i = 1; i < n; i++){ int u, v, iw; cin >> u >> v >> iw; g[u].pb(v); g[v].pb(u); w[{u, v}] = iw; w[{v, u}] = iw; edges.pb({u, v}); } int last = 0; while(qr--){ int ind, val; cin >> ind >> val; ind = (ind + last) % (n - 1); val = (val + last) % maxw; auto [x, y] = edges[ind]; w[{x, y}] = val; w[{y, x}] = val; vector<int> dis(n + 1, INF); dis[1] = 0; priority_queue<pair<int,int>, vector<pair<int,int> >, greater<pair<int,int> > > q; q.push({0, 1}); while(!q.empty()){ auto [disv, v] = q.top(); q.pop(); if(disv > dis[v]) continue; for(auto to : g[v]){ if(dis[v] + w[{v, to}] < dis[to]){ dis[to] = dis[v] + w[{v, to}]; q.push({dis[to], to}); } } } dis[0] = 0; int mx = max_element(all(dis)) - dis.begin(); dis = vector<int>(n + 1, INF); dis[mx] = 0; q.push({0, mx}); while(!q.empty()){ auto [disv, v] = q.top(); q.pop(); if(disv > dis[v]) continue; for(auto to : g[v]){ if(dis[v] + w[{v, to}] < dis[to]){ dis[to] = dis[v] + w[{v, to}]; q.push({dis[to], to}); } } } dis[0] = 0; last = *max_element(all(dis)); cout << last << '\n'; } } main(){ ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); int tt = 1; //cin >> tt; while (tt--) { solve(); } }

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

diameter.cpp:84:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   84 | main(){
      | ^~~~
#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...