이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#include "traffic.h"
using namespace std;
typedef vector<int> vi;
typedef vector<pair<int,int>> vpi;
typedef long long ll;
#define FIO ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define FOR(i,a,b) for (int i = (a); i < (b); ++i)
#define F0R(i,a) FOR(i,0,a)
#define F1R(i,a) FOR(i,1,a)
#define ROF(i,a,b) for ( i = (b)-1; i >= (a); --i)
#define R0F(i,a) ROF(i,0,a)
#define trav(a,x) for (auto& a: x)
#define rsz resize
#define all(x) begin(x), end(x)
#define sz(x) (int)(x).size()
#define f first
#define s second
#define mp make_pair
#define pb push_back
void setIO(string name = "") {
ios_base::sync_with_stdio(0); cin.tie(0);
if (sz(name)) {
freopen((name+".in").c_str(), "r", stdin);
freopen((name+".out").c_str(), "w", stdout);
}
}
bool cmp(const pair<pair<int,int>,int>&a, const pair<pair<int,int>,int> &b)
{
return a.s>b.s;
}
bool cmp2(const pair<pair<int,int>,int>&a, const pair<pair<int,int>,int> &b)
{
return a.f.s>b.f.s;
}
const int SZ=1e6+1;
const int MOD=1e9+7;
vi adj[SZ];
bool vis[SZ];
ll total=0;
void dfs(int node, int parent, int P[])
{
total+=P[node];
trav(x, adj[node])
{
if(x!=parent)
dfs(x, node , P);
}
}
ll solve(int node, int P[])
{
ll m=0;
trav(x, adj[node])
{
total=0;
dfs(x, node, P);
m=fmax(m, total);
// cout<<total<<' '<<x<<' '<<node<<endl;
}
return m;
}
int LocateCentre(int N,int P[],int S[], int D[]) {
FIO;
for(int i=0; i<N-1; i++)
{
adj[S[i]].pb(D[i]);
adj[D[i]].pb(S[i]);
}
ll ans=0, ansMin=INT_MAX;
F0R(i, N)
{
memset(vis, 0, SZ);
ll a=solve(i, P);
if(a<ansMin)
{
ans=i;
ansMin=a;
}
}
return ans+1;
}
//int main() {
// int P[5] = {10,10,10,20,20};
// int S[4] = {1, 2, 2, 3};
// int D[4] = {2, 0, 3, 4};
// //cout << LocateCentre(5, P, S, D);
// }
컴파일 시 표준 에러 (stderr) 메시지
traffic.cpp: In function 'void setIO(std::string)':
traffic.cpp:26:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
26 | freopen((name+".in").c_str(), "r", stdin);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
traffic.cpp:27:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
27 | freopen((name+".out").c_str(), "w", stdout);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# | 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... |