zoukankan      html  css  js  c++  java
  • Codeforces Round #626 (Div. 1, based on Moscow Open Olympiad in Informatics)C(二分图,哈希)

    把连接了相同左侧点的右侧点合并,对剩余右侧点求gcd。

     1 #define HAVE_STRUCT_TIMESPEC
     2 #include<bits/stdc++.h>
     3 using namespace std;
     4 long long a[500007];
     5 vector<int>edge[500007];
     6 int main(){
     7     ios::sync_with_stdio(false);
     8     cin.tie(NULL);
     9     cout.tie(NULL);
    10     int t;
    11     cin>>t;
    12     while(t--){
    13         int n,m;
    14         cin>>n>>m;
    15         for(int i=1;i<=n;++i){
    16             cin>>a[i];
    17             edge[i].clear();
    18         }
    19         for(int i=1;i<=m;++i){
    20             int u,v;
    21             cin>>u>>v;
    22             edge[v].emplace_back(u);
    23         }
    24         map<vector<int> ,long long>mp;
    25         for(int i=1;i<=n;++i){
    26             if(edge[i].size()>0){
    27                 sort(edge[i].begin(),edge[i].end());
    28                 mp[edge[i]]+=a[i];
    29             }
    30         }
    31         long long ans=0;
    32         for(auto it:mp){
    33             ans=__gcd(ans,it.second);
    34         }
    35         cout<<ans<<"
    ";
    36     }
    37     return 0;
    38 }
  • 相关阅读:
    蛋糕多少钱?
    【FJOI2015】金币换位问题
    撞车
    【BZOJ 1097】旅游景点atr
    codeforces 434D
    codeforces 480D
    bzoj网络流
    bzoj2039
    bzoj1927
    bzoj1070
  • 原文地址:https://www.cnblogs.com/ldudxy/p/12467015.html
Copyright © 2011-2022 走看看