QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#387623 | #3734. Parenthesis | ucup-team1251 | WA | 0ms | 9640kb | C++17 | 1.3kb | 2024-04-12 17:46:05 | 2024-04-12 17:46:05 |
Judging History
answer
#include<bits/stdc++.h>
#define mem(i,a) memset(i,a,sizeof(i))
#define inf 0x3f3f3f3f3f3f3f3f
#define PII pair<int,int>
#define int long long
#define endl '\n'
using namespace std;
const int N = 1e5 + 5,mod=1e9+7;
vector<int>g[N];
int sum[N],a[N],b[N],d[N];
vector<int>ans;
int n,m;
void tp()
{
queue<int>q;
for(int i=1;i<=n;i++)
{
if(d[i]==0)
q.push(i);
}
ans.clear();
while(!q.empty())
{
int u=q.front();
q.pop();
ans.push_back(u);
for(int i=0;i<g[u].size();i++)
{
d[g[u][i]]--;
if(d[g[u][i]]==0)
q.push(g[u][i]);
}
}
return ;
}
void solve() {
while(cin>>n>>m)
{
vector<int>q[N];
for(int i=1;i<=n;i++)
{
cin>>a[i]>>b[i];
g[i].clear();
sum[i]=0;
}
int u,v;
for(int i=1;i<=m;i++)
{
cin>>u>>v;
if(a[u]!=0&&b[v]!=0)
{
g[u].push_back(v);
q[v].push_back(u);
}
}
for(int i=1;i<=n;i++)
{
d[i]=(int)q[i].size();
}
tp();
for(int i=0;i<ans.size();i++)
{
for(int j=0;j<g[ans[i]].size();j++)
{
sum[g[ans[i]][j]]=(sum[g[ans[i]][j]]+a[ans[i]])%mod;
}
}
int ans1=0;
for(int i=1;i<=n;i++)
{
// cout<<sum[i]<<" ";
ans1=(ans1+sum[i]*b[i]%mod)%mod;
}
cout<<ans1<<endl;
}
}
signed main() {
cin.tie(0);
cout.tie(0);
ios::sync_with_stdio(0);
// int _;
// cin >> _;
// while (_--)
solve();
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Wrong Answer
time: 0ms
memory: 9640kb
input:
10 100 (()())()() 1 2 4 2 3 1 2 3 4 1 3 2 5 4 2 4 1 5 4 3 3 5 3 1 5 3 2 5 4 5 3 5 4 2 5 4 3 5 2 3 4 1 2 4 2 5 2 5 3 4 4 1 5 1 1 2 5 1 2 3 4 2 1 3 2 3 2 1 4 1 1 5 5 1 3 4 3 4 1 5 1 4 1 3 4 1 3 5 1 2 3 1 1 2 2 3 5 3 2 1 3 5 1 5 5 4 2 1 1 4 4 5 4 1 4 1 2 4 5 3 5 4 3 2 3 5 5 4 3 5 1 4 5 1 1 5 3 2 3 4 2 ...
output:
0
result:
wrong answer 1st words differ - expected: 'Yes', found: '0'