답안 #210940

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
210940 2020-03-19T03:18:44 Z HNO2 Designated Cities (JOI19_designated_cities) C++17
7 / 100
355 ms 39288 KB
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
const int maxn=2e5+7;
const int inf=INT_MAX;
const ll inff=1e18;
const ll mod=1e9+7;
#define pii pair<int,int>
#define mkp make_pair
#define F first
#define S second
#define pb push_back
#define sz(v) ((int)(v).size())
#define all(v) (v).begin(),(v).end()
#define int ll

#ifdef HNO2
#define IOS
#else
#define endl '\n'
#define IOS ios::sync_with_stdio(0); cin.tie(0);
#endif // HNO2

int x[maxn*2],y[maxn*2],w[maxn*2];
vector <int> G[maxn];

int ans[maxn];
int tmpsum=0;

void dfs(int now,int p)
{
    for (int i:G[now])
        if ((x[i]^y[i]^now)!=p)
    {
        ans[1]+=w[i];
        dfs((x[i]^y[i]^now),now);
    }
}

void dfs2(int now,int p)
{
    ans[1]=min(ans[1],tmpsum);
    for (int i:G[now])
        if ((x[i]^y[i]^now)!=p)
    {
        tmpsum-=(w[i]-w[i^1]);
        dfs2((x[i]^y[i]^now),now);
        tmpsum+=(w[i]-w[i^1]);
    }
}

int32_t main()
{
    IOS
    int n;
    cin>>n;
    for (int i=1;i<=n;i++) ans[i]=inff;

    int _=0;
    for (int i=1;i<=n-1;i++)
    {
        int X,Y,Z,W;
        cin>>X>>Y>>Z>>W;
        x[_]=X,y[_]=Y,w[_]=Z;
        x[_^1]=Y,y[_^1]=X,w[_^1]=W;
        G[X].pb(_);
        G[Y].pb(_^1);
        _+=2;
    }
    //1: calculate ans[1]
    ans[1]=0;
    dfs(1,-1);
    tmpsum=ans[1];
    dfs2(1,-1);
    //
    //2: ans[2]
    //
    //2: using ans[2] to calculate ans[i]
    //
    int q;
    cin>>q;
    while (q--)
    {
        int X;
        cin>>X;
        cout<<ans[X]<<endl;
    }
    //
}

# 결과 실행 시간 메모리 Grader output
1 Incorrect 7 ms 4992 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 5120 KB Output is correct
2 Correct 308 ms 29856 KB Output is correct
3 Correct 355 ms 38776 KB Output is correct
4 Correct 286 ms 28412 KB Output is correct
5 Correct 251 ms 29680 KB Output is correct
6 Correct 284 ms 31096 KB Output is correct
7 Correct 221 ms 29800 KB Output is correct
8 Correct 343 ms 39288 KB Output is correct
9 Correct 168 ms 30308 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 8 ms 4992 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 7 ms 4992 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 5120 KB Output is correct
2 Correct 308 ms 29856 KB Output is correct
3 Correct 355 ms 38776 KB Output is correct
4 Correct 286 ms 28412 KB Output is correct
5 Correct 251 ms 29680 KB Output is correct
6 Correct 284 ms 31096 KB Output is correct
7 Correct 221 ms 29800 KB Output is correct
8 Correct 343 ms 39288 KB Output is correct
9 Correct 168 ms 30308 KB Output is correct
10 Incorrect 8 ms 4992 KB Output isn't correct
11 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 7 ms 4992 KB Output isn't correct
2 Halted 0 ms 0 KB -