# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
376659 | daniel920712 | Designated Cities (JOI19_designated_cities) | C++14 | 621 ms | 92396 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <vector>
#include <map>
#include <set>
using namespace std;
vector < pair < long long , long long > > Next[200005];
map < long long , long long > all[200005];
set < long long > vis[200005];
long long ans[200005];
long long xx[200005];
long long how[200005];
long long N=0;
pair < long long , long long > A,B;
void F(long long here,long long fa)
{
for(auto i:Next[here])
{
if(i.first!=fa)
{
ans[1]+=i.second;
F(i.first,here);
}
}
}
void F2(long long here,long long fa)
{
for(auto i:Next[here])
{
if(i.first!=fa)
{
ans[i.first]=ans[here]-all[here][i.first]+all[i.first][here];
F2(i.first,here);
}
}
}
void F3(long long here,long long fa)
{
for(auto i:Next[here])
{
if(i.first!=fa)
{
vis[here].insert(i.first);
F3(i.first,here);
}
}
}
pair < long long , long long > F4(long long here,long long fa,long long con)
{
pair < long long , long long > a=make_pair(0,here),b=make_pair(0,here),tt;
for(auto i:Next[here])
{
if(i.first!=fa)
{
tt=F4(i.first,here,con+i.second);
if(tt>a)
{
b=a;
a=tt;
}
else if(tt>b)
{
b=tt;
}
}
}
A=a;
B=b;
return a;
}
int main()
{
long long M,i,j,k,a,b,c,d,where;
scanf("%lld",&N);
for(i=1;i<N;i++)
{
scanf("%lld %lld %lld %lld",&a,&b,&c,&d);
Next[a].push_back(make_pair(b,c));
Next[b].push_back(make_pair(a,d));
all[a][b]=c;
all[b][a]=d;
}
for(i=1;i<=N;i++) xx[i]=1e18;
if(N<=16)
{
for(i=0;i<(1<<N);i++)
{
a=0;
b=0;
for(j=1;j<=N;j++) vis[j].clear();
for(j=0;j<N;j++)
{
if(i&(1<<j))
{
F3(j+1,-1);
a++;
}
}
for(j=1;j<=N;j++) for(auto k:Next[j]) if(vis[j].find(k.first)==vis[j].end()) b+=all[k.first][j];
xx[a]=min(xx[a],b);
}
scanf("%lld",&M);
while(M--)
{
scanf("%lld",&a);
printf("%lld\n",xx[a]);
}
}
else
{
F(1,-1);
F2(1,-1);
how[1]=1e18;
for(i=1;i<=N;i++)
{
how[1]=min(how[1],ans[i]);
if(how[1]==ans[i]) where=i;
}
F4(1,-1,0);
how[2]=how[1]-A.first-B.first;
scanf("%lld",&M);
while(M--)
{
scanf("%lld",&a);
printf("%lld\n",how[a]);
}
}
return 0;
}
컴파일 시 표준 에러 (stderr) 메시지
# | 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... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |