Submission #946353

#TimeUsernameProblemLanguageResultExecution timeMemory
946353thunoproPaths (RMI21_paths)C++14
12 / 100
57 ms17016 KiB
#include<bits/stdc++.h> using namespace std ; #define maxn 200009 #define ll long long #define fi first #define se second #define pb push_back #define left id<<1 #define right id<<1|1 #define re exit(0); #define _lower(x) lower_bound(v.begin(),v.end(),x)-v.begin() #define TIME 1.0*clock()/CLOCKS_PER_SEC const int mod = 1e9+7; const int INF = 1e9; typedef vector<int> vi; typedef pair<int,int> pii; typedef vector<pii> vii; typedef vector<ll> vl; void add ( int &a , int b ) { a += b ; if ( a > mod ) a -= mod ; if ( a < 0 ) a += mod ; } template <typename T> void chkmin ( T &a , T b ) { if ( a > b ) a = b ; } template <typename T> void chkmax ( T &a , T b ) { if ( a < b ) a = b ; } int _pow ( int a , int n ) { if ( n == 0 ) return 1 ; int res = _pow (a,n/2) ; if ( n % 2 ) return 1ll*res*res%mod*a%mod ; else return 1ll*res*res%mod ; } void rf () { freopen ("bai1.inp","r",stdin) ; } int n , k ; vii adjList [maxn] ; ll d1 [maxn] , d2 [maxn] , d [maxn] ; int pos ; ll best = 0 ; void bfs ( int u ) { memset ( d , 0x3f , sizeof d ) ; queue <int> q ; d [u] = 0 ; q . push (u) ; while ( !q.empty() ) { int u = q.front() ; q.pop() ; for ( auto x : adjList [u] ) { int v = x.fi , w = x.se ; if ( d [v] > d [u] + w ) q . push (v) , d [v] = d [u] + w ; } } best = -1 ; for ( int i = 1 ; i <= n ; i ++ ) if ( d [i] > best ) best = d [i] , pos = i ; } int main () { ios_base::sync_with_stdio(0); cin.tie(0);cout.tie(0); // rf () ; cin >> n >> k ; for ( int i = 1 ; i < n ; i ++ ) { int u , v , w ; cin >> u >> v >> w ; adjList [u] . pb ({v,w}) ; adjList [v] . pb ({u,w}) ; } bfs (1) ; bfs (pos) ; for ( int i = 1 ; i <= n ; i ++ ) d1 [i] = d [i] ; bfs (pos) ; for ( int i = 1 ; i <= n ; i ++ ) d2 [i] = d [i] ; for ( int i = 1 ; i <= n ; i ++ ) cout << max (d1[i],d2[i]) << "\n" ; }

Compilation message (stderr)

Main.cpp: In function 'void rf()':
Main.cpp:42:10: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   42 |  freopen ("bai1.inp","r",stdin) ;
      |  ~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
#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...