結果

問題 No.1817 Reversed Edges
ユーザー 蜜蜂蜜蜂
提出日時 2022-01-21 21:48:44
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 190 ms / 2,000 ms
コード長 1,824 bytes
コンパイル時間 3,803 ms
コンパイル使用メモリ 228,772 KB
実行使用メモリ 19,916 KB
最終ジャッジ日時 2023-08-17 05:37:05
合計ジャッジ時間 8,744 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 2 ms
4,384 KB
testcase_05 AC 1 ms
4,380 KB
testcase_06 AC 1 ms
4,380 KB
testcase_07 AC 163 ms
9,628 KB
testcase_08 AC 75 ms
6,280 KB
testcase_09 AC 154 ms
9,416 KB
testcase_10 AC 89 ms
6,852 KB
testcase_11 AC 113 ms
7,840 KB
testcase_12 AC 188 ms
10,812 KB
testcase_13 AC 188 ms
10,808 KB
testcase_14 AC 184 ms
10,736 KB
testcase_15 AC 190 ms
10,804 KB
testcase_16 AC 184 ms
10,616 KB
testcase_17 AC 183 ms
10,752 KB
testcase_18 AC 183 ms
10,688 KB
testcase_19 AC 183 ms
10,692 KB
testcase_20 AC 185 ms
10,732 KB
testcase_21 AC 186 ms
10,812 KB
testcase_22 AC 154 ms
10,908 KB
testcase_23 AC 154 ms
10,912 KB
testcase_24 AC 169 ms
19,916 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: 関数 ‘int main()’ 内:
main.cpp:75:10: 警告: structured bindings only available with ‘-std=c++17’ or ‘-std=gnu++17’ [-Wc++17-extensions]
   75 |     auto [a,b]=v[i];
      |          ^

ソースコード

diff #

//g++ 1.cpp -std=c++14 -O2 -I .
#include <bits/stdc++.h>
using namespace std;

#include <atcoder/all>
using namespace atcoder;

using ll = long long;
using ld = long double;

using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vld = vector<ld>;
using vvld = vector<vld>;
using vst = vector<string>;
using vvst = vector<vst>;

#define fi first
#define se second
#define pb push_back
#define pq_big(T) priority_queue<T,vector<T>,less<T>>
#define pq_small(T) priority_queue<T,vector<T>,greater<T>>
#define all(a) a.begin(),a.end()
#define rep(i,start,end) for(ll i=start;i<(ll)(end);i++)
#define per(i,start,end) for(ll i=start;i>=(ll)(end);i--)
#define uniq(a) sort(all(a));a.erase(unique(all(a)),a.end())

void dfs(int now,int par,vi &dist,vvi &g){
  for(int next:g[now]){
    if(next==par)continue;
    dist[next]=dist[now]+1;
    dfs(next,now,dist,g);
  }
}

void dfs2(int now,int par,vi &del,vi &ans,vvi &g,int &val){
  val+=del[now];
  ans[now]=val;

  for(int next:g[now]){
    if(next==par)continue;
    dfs2(next,now,del,ans,g,val);
  }

  val-=del[now];
}

int main(){
  ios::sync_with_stdio(false);
  cin.tie(nullptr);

  int n;
  cin>>n;

  vvi g(n);
  vi dist(n,0);
  vector<pair<int,int>> v(n-1);
  rep(i,0,n-1){
    int a,b;
    cin>>a>>b;
    a--;b--;
    g[a].emplace_back(b);
    g[b].emplace_back(a);
    v[i]={a,b};
  }

  dfs(0,-1,dist,g);

  vi del(n,0);
  vi ans(n,0);

  rep(i,0,n-1){
    auto [a,b]=v[i];
    if(a>b){
      swap(a,b);
    }

    //<<dist[a]<<" "<<dist[b]<<endl;

    // dist[a]<dist[b] b側 +1
    // dist[a]>dist[b] a側 +1 = 全体 +1 - b側 +1

    if(dist[a]<dist[b]){
      del[b]++;
    }
    else{
      del[0]++;
      del[a]--;
    }
  }

  int val=0;
  dfs2(0,-1,del,ans,g,val);

  rep(i,0,n){
    cout<<ans[i]<<endl;
  }
}
0