QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#296839 | #7995. 图 | tarjen# | TL | 40ms | 4100kb | C++20 | 2.7kb | 2024-01-03 18:06:17 | 2024-01-03 18:06:17 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
const int maxn=510;
int a[maxn][maxn];
const int inf=1.5e9;
int ans[maxn][maxn];
typedef long long ll;
const ll p1=31,p2=131;
const ll mod1=1e9+7,mod2=1e9+9;
typedef pair<ll,ll> hs;
const hs p = make_pair(p1,p2);
hs &operator+=(hs &a, hs b) {
a.first=(a.first+b.first)%mod1;
a.second=(a.second+b.second)%mod2;
return a;
}
hs operator+(hs a, hs b) { return a += b; }
hs &operator-=(hs &a, hs b) {
a.first=(a.first-b.first+mod1)%mod1;
a.second=(a.second-b.second+mod2)%mod2;
return a;
}
hs operator-(hs a, hs b) { return a -= b; }
hs &operator*=(hs &a, hs b) {
a.first=(a.first*b.first)%mod1;
a.second=(a.second*b.second)%mod2;
return a;
}
hs operator*(hs a, hs b) { return a *= b; }
struct kkk{
int x,len;
hs c;
kkk(){}
kkk(int _x,int _len,hs _c){
x=_x,len=_len,c=_c;
}
bool operator<(kkk k1)const{
return len>k1.len;
}
};
int main(){
ios::sync_with_stdio(false);
cin.tie(0);
int n;cin>>n;
for(int i=1;i<=n;i++){
for(int j=1;j<=n;j++)cin>>a[i][j];
}
auto add= [&](hs &x,hs y){
x+=y;
};
auto solve = [&](int root){
vector<int> dis(n+1,inf);
vector<hs> cnt(n+1);
priority_queue<kkk,vector<kkk>> qu;
qu.push(kkk(root,0,{1,1}));
vector<int> lis;
while(!qu.empty()){
kkk k1=qu.top();qu.pop();
// cout<<"root="<<root<<" x="<<k1.x<<" len="<<k1.len<<"\n";
if(k1.len>dis[k1.x])continue;
if(k1.len<=dis[k1.x]){
add(cnt[k1.x],k1.c);
// cout<<"cnt="<<cnt[k1.x].first<<"\n";
}
if(k1.len<dis[k1.x]){
dis[k1.x]=k1.len;
lis.push_back(k1.x);
}
else continue;
for(int j=1;j<=n;j++)if(dis[k1.x]+a[k1.x][j]<=dis[j]){
qu.push(kkk{j,dis[k1.x]+a[k1.x][j],cnt[k1.x]});
}
}
cnt.clear();cnt.resize(n+1);
cnt[root]={1,1};
for(int i=0;i<n;i++){
for(int j=i+1;j<n;j++)if(dis[lis[i]]+a[lis[i]][lis[j]]==dis[lis[j]]){
add(cnt[lis[j]],cnt[lis[i]]);
}
}
for(int i=1;i<=n;i++){
for(int j=1;j<=n;j++)if(i!=j){
if(dis[i]+a[i][j]==dis[j]&&cnt[j]==cnt[i]){
ans[i][j]=1;
// if(i==1&&j==3)cout<<root<<"\n";
}
}
}
};
for(int i=1;i<=n;i++)solve(i);
for(int i=1;i<=n;i++){
for(int j=1;j<=n;j++)cout<<ans[i][j];;
cout<<"\n";
}
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 3572kb
input:
4 0 3 2 100 3 0 8 100 2 8 0 10 100 100 10 0
output:
0110 1000 1001 0010
result:
ok 4 lines
Test #2:
score: 0
Accepted
time: 1ms
memory: 3468kb
input:
4 0 3 2 100 3 0 8 100 2 8 0 10 100 100 10 0
output:
0110 1000 1001 0010
result:
ok 4 lines
Test #3:
score: 0
Accepted
time: 40ms
memory: 4044kb
input:
100 0 41659 61282 49636 67326 48035 29694 46438 87384 82143 38685 66540 48746 29800 91786 54931 56232 61941 53423 75707 45135 69244 53802 89998 64199 63778 75825 31745 66975 44537 35793 55663 72647 60768 80884 46657 54066 84568 6266 48213 78216 50369 66761 54861 67607 38509 52250 54210 71135 56840 5...
output:
0000000000000000000000000000000000000010000100000000100001001000000000000001000000000000000000000010 0011000000100000000000000000000000000000000000000000000000100000000000000000000000000000000000000000 01001000010000000000000000000000000000000000000000001000000010000000000010000000010000000000000000...
result:
ok 100 lines
Test #4:
score: 0
Accepted
time: 40ms
memory: 4088kb
input:
100 0 81722 50546 79959 47292 51747 54712 7396 58005 52529 61319 66453 61823 76359 55454 60837 29465 61066 66711 75051 58395 38189 44176 32315 39742 46514 23229 27872 59119 39600 81204 45383 59424 40396 51094 74411 16551 30485 42587 18676 82697 76869 48206 41961 44633 59558 41795 57384 59943 18175 4...
output:
0000000100000000000000000000000000000000000000000100000000000001000000000000000100000000000000000000 0000000000000001010100000000000000000000000000000000000100000000001000000000000000000000000000000000 00000000001000001000000000001000000000000000000000000000000000000000100000001000000001000000000000...
result:
ok 100 lines
Test #5:
score: 0
Accepted
time: 27ms
memory: 4100kb
input:
100 0 1 2 1 2 1 1 1 1 1 1 1 1 2 2 2 2 2 1 2 2 2 2 2 1 1 2 1 1 1 1 1 1 1 1 1 1 2 2 1 1 1 2 1 1 1 1 1 1 2 1 1 2 2 1 1 1 2 2 1 1 2 1 2 1 2 1 2 2 2 1 1 2 1 2 3 1 1 2 2 2 1 1 1 1 2 1 1 2 1 1 1 1 1 1 1 1 2 1 1 1 0 1 1 1 2 3 2 2 1 1 1 1 2 2 1 3 3 2 2 1 3 2 2 2 1 3 2 2 1 1 2 2 3 1 2 1 1 1 1 1 2 3 2 1 1 2 1 ...
output:
0101011111111000001000001101111111111001110111111011001110011010101000110100110001111011011111111011 1011100001111001000010000100011000101111100011010110000111101011101000010001010111011010111011101101 01000011010010010111101101101111110111110000101000101111100010110010011100110101101010100000110011...
result:
ok 100 lines
Test #6:
score: 0
Accepted
time: 40ms
memory: 4048kb
input:
100 0 2 2 1 2 2 2 2 1 2 2 2 1 1 2 1 2 1 2 2 2 3 2 2 2 2 1 1 1 2 1 2 1 2 1 2 1 2 2 2 2 1 1 1 1 1 1 2 2 2 1 1 2 2 2 1 2 2 1 1 3 1 1 2 2 2 2 1 2 1 3 2 1 2 1 1 1 1 2 2 1 1 1 2 2 2 1 2 2 1 1 2 1 1 3 1 1 3 2 1 2 0 1 1 2 1 2 2 2 2 1 3 2 2 2 1 1 1 2 3 1 1 1 2 1 2 2 2 1 1 2 2 1 1 2 1 1 2 2 1 2 1 1 1 2 2 1 1 ...
output:
0001000010001101010000000011101010101000011111100011000100110110000101001011110011100010011011011001 0011010000100001110011101000110011011001011100110110101100010010000110100111100111111010101001011011 01010001110101001110100011100011010010110000110001110101101010111001101010110001101110011101010111...
result:
ok 100 lines
Test #7:
score: -100
Time Limit Exceeded
input:
500 0 743810 457854 85842 793418 318922 803556 939014 213357 346386 67230 841985 991820 600886 111369 198349 745203 809216 581207 443436 374000 684975 536767 444827 513284 841566 95714 870537 213411 507714 279089 852847 236477 266161 457883 432456 181558 6690 709759 89446 718063 263025 285303 124290...