제출 #424047

#제출 시각아이디문제언어결과실행 시간메모리
424047chirathnirodhaTraffic (IOI10_traffic)C++17
0 / 100
14 ms23756 KiB
#include "traffic.h" #include<bits/stdc++.h> using namespace std; typedef long long ll; int n; ll subtree[1000000]; int parent[1000000]; vector<int> adj[1000000]; ll dfs(int x){ for(int i=0;i<adj[x].size();i++){ if(adj[x][i]==0 || parent[adj[x][i]]!=adj[x][i])continue; parent[adj[x][i]]=x; subtree[x]+=dfs(adj[x][i]); } return subtree[x]; } int LocateCentre(int N, int pp[], int S[], int D[]) { n=N; ll total=0; for(int i=0;i<n;i++){ subtree[i]=(long long) pp[i]; parent[i]=i; total+=subtree[i]; } for(int i=0;i<n-1;i++){adj[S[i]].push_back(D[i]);adj[D[i]].push_back(S[i]);} dfs(0); int child[n];child[0]=adj[0].size(); queue<int> q; for(int i=1;i<n;i++){ child[i]=adj[i].size()-1; if(child[i]==0)q.push(i); } ll cost[n];memset(cost,0,sizeof(cost)); while(!q.empty()){ int c=q.front();q.pop(); if(parent[c]==c)continue; cost[c]+=total-subtree[c]; cost[parent[c]]+=subtree[c]; child[parent[c]]--; if(parent[parent[c]]!=parent[c] && child[parent[c]]==0)q.push(parent[c]); } pair<ll,int> ans;ans.first=cost[0];ans.second=0; for(int i=0;i<n;i++){ if(ans.first>cost[i]){ ans.first=cost[i]; ans.second=i; } } return ans.second; }

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

traffic.cpp: In function 'll dfs(int)':
traffic.cpp:11:17: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   11 |    for(int i=0;i<adj[x].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...