제출 #279659

#제출 시각아이디문제언어결과실행 시간메모리
279659infinite_iqDynamic Diameter (CEOI19_diameter)C++14
24 / 100
1225 ms7032 KiB
#define fast ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0) #include <bits/stdc++.h> using namespace std; #define sqr 340 #define mp make_pair #define mid (l+r)/2 #define le node * 2 #define ri node * 2 + 1 #define pb push_back #define ppb pop_back #define fi first #define se second #define lb lower_bound #define ub upper_bound #define ins insert #define era erase #define C continue #define mem(dp,i) memset(dp,i,sizeof(dp)) #define mset multiset #define all(x) x.begin(), x.end() #define gc getchar_unlocked typedef long long ll; typedef short int si; typedef long double ld; typedef pair<int,int> pi; typedef pair<ll,ll> pll; typedef vector<int> vi; typedef vector<ll> vll; typedef vector<pi> vpi; typedef vector<pll> vpll; typedef pair<double,ll>pdi; const ll inf=1e18; const ll Mod=1e9+7; const ld Pi=acos(-1) ; int n , q , MX ; vpi v [100009] ; pi edges [100009] ; void input () { cin >> n >> q >> MX ; for ( int i = 0 ; i < n - 1 ; i ++ ) { int a , b , c ; scanf ("%d%d%d", &a , &b , &c ) ; a -- , b -- ; edges [i] = { a , b } ; v [a] .pb ( { b , c } ) ; v [b] .pb ( { a , c } ) ; } } // Sub1_2 pi Mx ; int Sub1_2 () { return ( n <= 5009 && q <= 5009 ) ; } void Dfs1 ( int node , int p , int Crnt ) { Mx = max ( Mx , { Crnt , node } ) ; for ( auto u : v [node] ) { if ( u .fi == p ) C ; Dfs1 ( u .fi , node , Crnt + u .se ) ; } } int BruteForce () { Mx = { 0 , 0 } ; Dfs1 ( 0 , 0 , 0 ) ; Dfs1 ( Mx .se , Mx .se , 0 ) ; return Mx .fi ; } void Sol1_2 () { int Last = 0 ; while ( q -- ) { int id , cost ; cin >> id >> cost ; id = ( id + Last ) % ( n - 1 ) ; cost = ( cost + Last ) % ( MX ) ; int a = edges [id] .fi , b = edges [id] .se ; for ( auto &u : v [a] ) { if ( u .fi == b ) { u .se = cost ; break ; } } for ( auto &u : v [b] ) { if ( u .fi == a ) { u .se = cost ; break ; } } Last = BruteForce () ; cout << Last << endl ; } } int main () { input () ; if ( Sub1_2 () ) Sol1_2 () ; // if ( Sub4 () ) Sol4 () ; // if ( Sub3_5 () ) Sol3_5 () ; }

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

diameter.cpp: In function 'void input()':
diameter.cpp:42:23: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   42 |                 scanf ("%d%d%d", &a , &b , &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...