답안 #284713

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
284713 2020-08-27T22:32:31 Z ScarletS Pipes (BOI13_pipes) C++17
37.5926 / 100
256 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)
    {
        score[circle[i]]-=cur[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 50 ms 67704 KB Output isn't correct
2 Incorrect 50 ms 67704 KB Output isn't correct
3 Incorrect 50 ms 67704 KB Output isn't correct
4 Incorrect 111 ms 70176 KB Output isn't correct
5 Incorrect 50 ms 67712 KB Output isn't correct
6 Incorrect 52 ms 67704 KB Output isn't correct
7 Incorrect 52 ms 67704 KB Output isn't correct
8 Incorrect 50 ms 67704 KB Output isn't correct
9 Incorrect 51 ms 67704 KB Output isn't correct
10 Incorrect 52 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 102 ms 69624 KB Output isn't correct
14 Incorrect 115 ms 70052 KB Output isn't correct
15 Incorrect 113 ms 70136 KB Output isn't correct
16 Incorrect 105 ms 69752 KB Output isn't correct
17 Incorrect 126 ms 70136 KB Output isn't correct
18 Incorrect 116 ms 70136 KB Output isn't correct
19 Incorrect 112 ms 69880 KB Output isn't correct
20 Incorrect 49 ms 67704 KB Output isn't correct
21 Incorrect 65 ms 67704 KB Output isn't correct
22 Incorrect 124 ms 70136 KB Output isn't correct
23 Incorrect 106 ms 69624 KB Output isn't correct
24 Incorrect 123 ms 70136 KB Output isn't correct
25 Incorrect 103 ms 69752 KB Output isn't correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 56 ms 67704 KB Output isn't correct
2 Incorrect 59 ms 67704 KB Output isn't correct
3 Runtime error 233 ms 131072 KB Execution killed with signal 11
4 Correct 107 ms 68612 KB Output is correct
5 Correct 105 ms 68472 KB Output is correct
6 Correct 256 ms 68600 KB Output is correct
7 Incorrect 51 ms 67704 KB Output isn't correct
8 Runtime error 126 ms 131072 KB Execution killed with signal 11
9 Runtime error 126 ms 131072 KB Execution killed with signal 11
10 Correct 53 ms 67712 KB Output is correct
11 Correct 51 ms 67704 KB Output is correct
12 Correct 53 ms 67892 KB Output is correct
13 Correct 53 ms 67712 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 138 ms 131072 KB Execution killed with signal 11
17 Correct 53 ms 67704 KB Output is correct
18 Correct 53 ms 67704 KB Output is correct
19 Correct 53 ms 67656 KB Output is correct
20 Correct 52 ms 67704 KB Output is correct
21 Correct 53 ms 67688 KB Output is correct
22 Incorrect 51 ms 67704 KB Output isn't correct
23 Runtime error 207 ms 131072 KB Execution killed with signal 11
24 Runtime error 234 ms 131072 KB Execution killed with signal 11
25 Runtime error 229 ms 131072 KB Execution killed with signal 11
26 Correct 100 ms 68472 KB Output is correct
27 Correct 100 ms 68472 KB Output is correct
28 Correct 103 ms 68472 KB Output is correct
29 Correct 211 ms 68472 KB Output is correct
30 Runtime error 228 ms 131072 KB Execution killed with signal 11
31 Runtime error 236 ms 131072 KB Execution killed with signal 11
32 Incorrect 105 ms 69752 KB Output isn't correct
33 Runtime error 230 ms 131072 KB Execution killed with signal 11
34 Correct 102 ms 68600 KB Output is correct
35 Correct 106 ms 68472 KB Output is correct
36 Correct 103 ms 68472 KB Output is correct
37 Correct 247 ms 68616 KB Output is correct
38 Runtime error 232 ms 131072 KB Execution killed with signal 11
39 Runtime error 225 ms 131072 KB Execution killed with signal 11
40 Runtime error 226 ms 131072 KB Execution killed with signal 11
41 Runtime error 235 ms 131072 KB Execution killed with signal 11
42 Correct 98 ms 68472 KB Output is correct
43 Correct 102 ms 68492 KB Output is correct
44 Correct 105 ms 68600 KB Output is correct
45 Correct 220 ms 68088 KB Output is correct
46 Incorrect 104 ms 69624 KB Output isn't correct
47 Incorrect 106 ms 69752 KB Output isn't correct
48 Incorrect 103 ms 69624 KB Output isn't correct
49 Correct 104 ms 69692 KB Output is correct
50 Correct 101 ms 68472 KB Output is correct
51 Correct 99 ms 68488 KB Output is correct
52 Correct 100 ms 68480 KB Output is correct
53 Correct 225 ms 68216 KB Output is correct
54 Runtime error 229 ms 131072 KB Execution killed with signal 11