답안 #284710

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
284710 2020-08-27T22:24:37 Z ScarletS Pipes (BOI13_pipes) C++17
37.5926 / 100
261 ms 131072 KB
#include <bits/stdc++.h>
#define ll long long
#define sz(x) (int)(x).size()
#define pii pair<int,int>
using namespace std;

const int MAXN = 100001;
stack<pii> edges[MAXN];
int score[MAXN],amount[MAXN],x,d,n;
ll cur[MAXN],t;
int ans[5*MAXN];
bool done[MAXN];
vector<int> circle;
vector<int> vals;

void dfs(int c)
{
    done[c]=1;
    circle.push_back(c);
    if (d+sz(circle)==n)
        return;
    while (sz(edges[c]))
    {
        if (done[edges[c].top().first])
            edges[c].pop();
        else
        {
            vals.push_back(edges[c].top().second);
            dfs(edges[c].top().first);
        }
    }
}

int main()
{
    ios_base::sync_with_stdio(0); cin.tie(0);
    int m,u,v;
    cin>>n>>m;
    for (int i = 1; i <= n; ++i)
        cin>>score[i];
    for (int i = 0; i < m; ++i)
    {
        cin>>u>>v;
        edges[u].push({v,i});
        edges[v].push({u,i});
        ++amount[u];
        ++amount[v];
    }
    if (m>n)
    {
        cout<<"0\n";
        return 0;
    }
    stack<int> s;
    for (int i=1;i<=n;++i)
        if (amount[i]==1)
            s.push(i);
    while (sz(s))
    {
        ++x;
        ++d;
        u=s.top();
        s.pop();
        while (done[edges[u].top().first])
            edges[u].pop();
        v=edges[u].top().first;
        ans[edges[u].top().second]=score[u]-cur[u];
        cur[u]+=ans[edges[u].top().second];
        cur[v]+=ans[edges[u].top().second];
        //ans[edges[u].top().second]<<=1;
    }
    if (m==n-1)
    {
        for (int i=0;i<m;++i)
            cout<<ans[i]*2<<"\n";
        return 0;
    }
    if ((n-x+1)&1)
    {
        cout<<"0\n";
        return 0;
    }
    for (int i=1;i<=n;++i)
    {
        while (sz(edges[u])&&done[edges[u].top().first])
            edges[u].pop();
        if (sz(edges[u]))
            x=u;
    }
    dfs(x);
    while (edges[circle.back()].top().first!=circle[0])
        edges[circle.back()].pop();
    vals.push_back(edges[circle.back()].top().second);
    /**for (int i : circle)
        cout<<i<<" ";
    cout<<"\n";**/
    for (int i=0;i<sz(circle);++i)
    {
        if (i&1)
            t-=score[circle[i]];
        else
            t+=score[circle[i]];
    }
    ans[vals.back()]=t/2;
    ans[vals[0]]=score[circle[0]]-ans[vals.back()];
    for (int i=1;i+1<sz(circle);++i)
    {
        //cout<<"ans[vals[{"<<circle[i]<<","<<circle[i+1]<<"}] = "<<score[circle[i]]<<" - "<<ans[vals[{circle[i],circle[i-1]}]]<<"\n";
        ans[vals[i]]=score[circle[i]]-ans[vals[i-1]];
    }
    for (int i=0;i<m;++i)
        cout<<ans[i]*2<<"\n";
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Incorrect 52 ms 67708 KB Output isn't correct
2 Incorrect 52 ms 67712 KB Output isn't correct
3 Incorrect 53 ms 67704 KB Output isn't correct
4 Incorrect 114 ms 70136 KB Output isn't correct
5 Incorrect 51 ms 67704 KB Output isn't correct
6 Incorrect 52 ms 67608 KB Output isn't correct
7 Incorrect 52 ms 67704 KB Output isn't correct
8 Incorrect 52 ms 67708 KB Output isn't correct
9 Incorrect 52 ms 67704 KB Output isn't correct
10 Incorrect 53 ms 67704 KB Output isn't correct
11 Incorrect 52 ms 67704 KB Output isn't correct
12 Incorrect 52 ms 67704 KB Output isn't correct
13 Incorrect 99 ms 69624 KB Output isn't correct
14 Incorrect 113 ms 70008 KB Output isn't correct
15 Incorrect 116 ms 70136 KB Output isn't correct
16 Incorrect 108 ms 69752 KB Output isn't correct
17 Incorrect 119 ms 70136 KB Output isn't correct
18 Incorrect 115 ms 70136 KB Output isn't correct
19 Incorrect 110 ms 69880 KB Output isn't correct
20 Incorrect 52 ms 67704 KB Output isn't correct
21 Incorrect 52 ms 67704 KB Output isn't correct
22 Incorrect 114 ms 70136 KB Output isn't correct
23 Incorrect 102 ms 69628 KB Output isn't correct
24 Incorrect 115 ms 70136 KB Output isn't correct
25 Incorrect 102 ms 69752 KB Output isn't correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 52 ms 67884 KB Output isn't correct
2 Incorrect 53 ms 67704 KB Output isn't correct
3 Runtime error 237 ms 131072 KB Execution killed with signal 11
4 Correct 106 ms 68472 KB Output is correct
5 Correct 98 ms 68472 KB Output is correct
6 Correct 261 ms 74616 KB Output is correct
7 Incorrect 51 ms 67704 KB Output isn't correct
8 Runtime error 127 ms 131072 KB Execution killed with signal 11
9 Runtime error 135 ms 131072 KB Execution killed with signal 11
10 Correct 52 ms 67704 KB Output is correct
11 Correct 51 ms 67704 KB Output is correct
12 Correct 50 ms 67704 KB Output is correct
13 Correct 51 ms 67704 KB Output is correct
14 Incorrect 51 ms 67704 KB Output isn't correct
15 Incorrect 53 ms 67704 KB Output isn't correct
16 Runtime error 129 ms 131072 KB Execution killed with signal 11
17 Correct 52 ms 67704 KB Output is correct
18 Correct 54 ms 67712 KB Output is correct
19 Correct 52 ms 67704 KB Output is correct
20 Correct 52 ms 67704 KB Output is correct
21 Correct 52 ms 67704 KB Output is correct
22 Incorrect 61 ms 67704 KB Output isn't correct
23 Runtime error 218 ms 131072 KB Execution killed with signal 11
24 Runtime error 240 ms 131072 KB Execution killed with signal 11
25 Runtime error 227 ms 131072 KB Execution killed with signal 11
26 Correct 108 ms 68476 KB Output is correct
27 Correct 103 ms 68472 KB Output is correct
28 Correct 102 ms 68472 KB Output is correct
29 Correct 218 ms 68472 KB Output is correct
30 Runtime error 232 ms 131072 KB Execution killed with signal 11
31 Runtime error 236 ms 131072 KB Execution killed with signal 11
32 Incorrect 118 ms 69808 KB Output isn't correct
33 Runtime error 229 ms 131072 KB Execution killed with signal 11
34 Correct 100 ms 68472 KB Output is correct
35 Correct 102 ms 68600 KB Output is correct
36 Correct 104 ms 68472 KB Output is correct
37 Correct 252 ms 74620 KB Output is correct
38 Runtime error 250 ms 131072 KB Execution killed with signal 11
39 Runtime error 226 ms 131072 KB Execution killed with signal 11
40 Runtime error 227 ms 131072 KB Execution killed with signal 11
41 Runtime error 253 ms 131072 KB Execution killed with signal 11
42 Correct 101 ms 68472 KB Output is correct
43 Correct 107 ms 68472 KB Output is correct
44 Correct 103 ms 68472 KB Output is correct
45 Correct 212 ms 68248 KB Output is correct
46 Incorrect 101 ms 69624 KB Output isn't correct
47 Incorrect 105 ms 69752 KB Output isn't correct
48 Incorrect 108 ms 69752 KB Output isn't correct
49 Correct 105 ms 69692 KB Output is correct
50 Correct 102 ms 68472 KB Output is correct
51 Correct 103 ms 68600 KB Output is correct
52 Correct 106 ms 68600 KB Output is correct
53 Correct 229 ms 68372 KB Output is correct
54 Runtime error 234 ms 131072 KB Execution killed with signal 11