제출 #276003

#제출 시각아이디문제언어결과실행 시간메모리
276003FashoDynamic Diameter (CEOI19_diameter)C++14
0 / 100
624 ms14588 KiB
#include <bits/stdc++.h> #define N 100005 #define ll long long int #define fo(i,x,y) for(int i=x;i<=y;i++) #define fs(ar,n) fo(i,1,n) cin>>ar[i] #define sp " " #define fast cin.tie(0);cout.tie(0);ios_base::sync_with_stdio(false) #define pb push_back #define ppb pop_back #define fi first #define se second #define ii pair<int,int> #define lli pair<ll,ll> #define mod 1000000007 using namespace std; ll n,m,ar[N],sum,t,mki1,mki2,mk,mk1,mk2; pair<lli,ll> p[N]; multiset<ll> st; vector<int> v[N]; void f(int ind,int back,int dist) { if(dist>mk) { mk=dist, mki1=ind; } for(int i=0;i<v[ind].size();i++) { ll x=p[v[ind][i]].fi.fi; if(x==ind) x=p[v[ind][i]].fi.se; ll y=p[v[ind][i]].se; if(x==back) continue; f(x,ind,dist+y); } } ll calc() { mk=0; f(1,1,0); swap(mki1,mki2); mk=0; f(mki2,mki2,0); return mk; } int main() { fast; ll bos; cin>>n>>m>>bos; fo(i,1,n-1) { ll a,b,c; cin>>a>>b>>c; v[a].pb(i); v[b].pb(i); p[i]={{a,b},c}; st.insert(c); if(mki2!=i) { if(mk2<c) mk2=c,mki2=i; } if(mk1<mk2) { swap(mki1,mki2); swap(mk1,mk2); } } ll last=0; cout<<st.size()<<endl; fo(i,1,m) { ll x, y; cin>>x>>y; if(i!=1) { x=(x+last)%(n-1); y=(y+last)%bos; } ll tt=p[x+1].se; auto it=st.find(tt); st.erase(it); st.insert(y); p[x+1].se=y; it=st.end(); it--; ll a=*it; st.erase(it); it=st.end(); it--; ll b=*it; last=a+b; // cout<<"[ans]"<<endl; // cerr<<a<<sp<<b<<endl; cout<<last<<endl; st.insert(a); // cerr<<"[d]"<<endl; } }

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

diameter.cpp: In function 'void f(int, int, int)':
diameter.cpp:30:15: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   30 |  for(int i=0;i<v[ind].size();i++)
      |              ~^~~~~~~~~~~~~~
#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...