제출 #279658

#제출 시각아이디문제언어결과실행 시간메모리
279658infinite_iqDynamic Diameter (CEOI19_diameter)C++14
11 / 100
5058 ms21620 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 ; vi v [100009] ; pi edges [100009] ; map < pi , int > wight ; 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 } ; wight [ mp ( a , b ) ] = wight [ mp ( b , a ) ] = c ; v [a] .pb ( b ) ; v [b] .pb ( a ) ; } } // 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 == p ) C ; Dfs1 ( u , node , Crnt + wight [ mp ( node , u ) ] ) ; } } 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 ; wight [ mp ( a , b ) ] = wight [ mp ( b , a ) ] = cost ; 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:43:23: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   43 |                 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...