Submission #240626

# Submission time Handle Problem Language Result Execution time Memory
240626 2020-06-20T10:03:32 Z mhy908 Rigged Roads (NOI19_riggedroads) C++14
19 / 100
443 ms 74808 KB
#include <bits/stdc++.h>
#define eb emplace_back
#define mp make_pair
#define F first
#define S second
#define all(x) x.begin(), x.end()
#define svec(x) sort(x.begin(), x.end())
#define press(x) x.erase(unique(x.begin(), x.end()), x.end())
#define lb(x, v) lower_bound(x.begin(), x.end(), v)
#define ub(x, v) upper_bound(x.begin(), x.end(), v)
using namespace std;
typedef long long LL;
typedef pair<int, int> pii;
typedef pair<LL, LL> pll;
typedef pair<int, LL> pil;
typedef pair<LL, int> pli;
const LL llinf=2000000000000000000;
const LL mod1=1000000007;
const LL mod2=998244353;
const int inf=2000000000;
int n, m, ans[300010];
pii edge[300010];
bool ch[300010];
vector<int> link[300010];
int d[300010], sp[300010][30], num, p[300010], cnt[300010];
void dfs(int num, int par){
    d[num]=d[par]+1, sp[num][0]=par, p[num]=num;
    for(auto i:link[num]){
        if(i!=par)dfs(i, num);
    }
}
int lca(int x, int y){
    if(d[x]>d[y])swap(x, y);
    for(int i=19; i>=0; i--){
        if(d[y]-d[x]>=(1<<i))y=sp[y][i];
    }
    if(x==y)return x;
    for(int i=19; i>=0; i--){
        if(sp[x][i]!=sp[y][i]){
            x=sp[x][i];
            y=sp[y][i];
        }
    }
    return sp[x][0];
}
int main(){
    scanf("%d %d", &n, &m);
    for(int i=1; i<=m; i++)scanf("%d %d", &edge[i].F, &edge[i].S);
    for(int i=1; i<n; i++){
        int a;
        scanf("%d", &a);
        ch[a]=true;
        link[edge[a].F].eb(edge[a].S);
        link[edge[a].S].eb(edge[a].F);
    }
    dfs(1, 0);
    for(int j=1; j<20; j++){
        for(int i=1; i<=n; i++)sp[i][j]=sp[sp[i][j-1]][j-1];
    }
    for(int i=1; i<=m; i++){
        if(d[edge[i].F]<d[edge[i].S])swap(edge[i].F, edge[i].S);
        if(ch[i])cnt[edge[i].F]=i;
    }
    for(int i=1; i<=m; i++){
        if(ans[i])continue;
        if(ch[i]){
            ans[i]=++num;
            p[edge[i].F]=p[edge[i].S];
            continue;
        }
        int l=lca(edge[i].F, edge[i].S);
        int a=p[edge[i].F], b=p[edge[i].S];
        vector<int> vc;
        while(d[a]>d[l]){vc.eb(cnt[a]); p[a]=p[l]; a=p[sp[a][0]];}
        while(d[b]>d[l]){vc.eb(cnt[b]); p[b]=p[l]; b=p[sp[b][0]];}
        svec(vc);
        for(auto j:vc)ans[j]=++num;
        ans[i]=++num;
    }
    for(int i=1; i<=m; i++)printf("%d ", ans[i]);
}

Compilation message

riggedroads.cpp: In function 'int main()':
riggedroads.cpp:47:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d %d", &n, &m);
     ~~~~~^~~~~~~~~~~~~~~~~
riggedroads.cpp:48:33: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     for(int i=1; i<=m; i++)scanf("%d %d", &edge[i].F, &edge[i].S);
                            ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
riggedroads.cpp:51:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d", &a);
         ~~~~~^~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 9 ms 7424 KB Output is correct
2 Correct 9 ms 7424 KB Output is correct
3 Incorrect 8 ms 7424 KB Output isn't correct
# Verdict Execution time Memory Grader output
1 Correct 9 ms 7424 KB Output is correct
2 Correct 9 ms 7424 KB Output is correct
3 Incorrect 8 ms 7424 KB Output isn't correct
# Verdict Execution time Memory Grader output
1 Correct 87 ms 26884 KB Output is correct
2 Correct 167 ms 34528 KB Output is correct
3 Correct 145 ms 19064 KB Output is correct
4 Correct 257 ms 61284 KB Output is correct
5 Correct 255 ms 64100 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 165 ms 34208 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 343 ms 61980 KB Output is correct
2 Correct 357 ms 68676 KB Output is correct
3 Correct 93 ms 24596 KB Output is correct
4 Correct 134 ms 33424 KB Output is correct
5 Correct 443 ms 74808 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 260 ms 44000 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 9 ms 7424 KB Output is correct
2 Correct 9 ms 7424 KB Output is correct
3 Incorrect 8 ms 7424 KB Output isn't correct