This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include "traffic.h"
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define INF 1e18//change to const int INF=1e18 if causing problem
const ll MOD=998244353;
const ll alt=1e10;
const ll inf=1e9+7;//Precalc is not a bad idea
//#define int ll
#define pb push_back
#define pf push_front
#define mp make_pair
#define fi first
#define se second
#define mod(a) (a+inf)%inf
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define sz(a) a.size()
vector<int> adj[100000];
priority_queue<pair<int,int>,vector<pair<int,int> >,greater<pair<int,int> > > q;
vector<int> vis(100000,0);
vector<bool> visd(100000,false);
int LocateCentre(int N, int pp[], int s[], int d[]){
for(int i=0;i<N;i++){
adj[s[i]].pb(d[i]);
adj[d[i]].pb(s[i]);
}
for(int i=0;i<N;i++){
if(adj[i].size()==1){
q.push(mp(pp[i],i));
visd[i]=true;
}
}
while(sz(q)>1){
int a=q.top().fi,b=q.top().se;
q.pop();
int y=0;
for(int i=0;i<sz(adj[b]);i++){
if(!visd[adj[b][i]]){
y=i;
break;
}
}
pp[adj[b][y]]+=a;
vis[adj[b][y]]+=1;
if(sz(adj[adj[b][y]])-vis[adj[b][y]]==1){
q.push(mp(pp[adj[b][y]],adj[b][y]));
visd[adj[b][y]]=true;
}
}
return q.top().se;
}
//Icebear16
Compilation message (stderr)
traffic.cpp: In function 'int LocateCentre(int, int*, int*, int*)':
traffic.cpp:40:16: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
40 | for(int i=0;i<sz(adj[b]);i++){
| ^
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |