Submission #58723312
Source Code Expand
Copy
#include<bits/stdc++.h>#define TxtIO freopen("input.txt","r",stdin); freopen("output.txt","w",stdout); freopen("error.txt","w", stderr) ;using namespace std;#include <ext/pb_ds/assoc_container.hpp>#include <ext/pb_ds/tree_policy.hpp>using namespace __gnu_pbds;#define oset tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>typedef long long tds;vector<vector<tds>> floydw(int n, vector<pair<int,tds>> adj[]){//tds INF=INT64_MAX;//vector<vector<tds>> dist(n,vector<tds> (n,INF));for(int i=0;i<n;i++){dist[i][i]=0;}for(int i=0;i<n;i++){for(auto j: adj[i]){dist[i][j.first]=min(dist[i][j.first],j.second);
#include<bits/stdc++.h> #define TxtIO freopen("input.txt","r",stdin); freopen("output.txt","w",stdout); freopen("error.txt","w", stderr) ; using namespace std; #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> using namespace __gnu_pbds; #define oset tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update> typedef long long tds; vector<vector<tds>> floydw(int n, vector<pair<int,tds>> adj[]){ // tds INF=INT64_MAX; // vector<vector<tds>> dist(n,vector<tds> (n,INF)); for(int i=0;i<n;i++){ dist[i][i]=0; } for(int i=0;i<n;i++){ for(auto j: adj[i]){ dist[i][j.first]=min(dist[i][j.first],j.second); } } for(int k=0;k<n;k++){ for(int i=0;i<n;i++){ for(int j=0;j<n;j++){ if(dist[i][k]<INF && dist[k][j]<INF){ dist[i][j]=min(dist[i][j],dist[i][k]+dist[k][j]); } } } } for(int i=0;i<n;i++){ for(int j=0;j<n;j++){ if(dist[i][j]==INF){ dist[i][j]=-1; } } } return dist; } int main(){ int n,m,q; cin>>n>>m>>q; vector<pair<int,pair<int,tds>>> v(m); vector<pair<int,tds>> adj[n]; for(int i=0;i<m;i++){ int a,b;long long c; cin>>a>>b>>c; a--;b--; v[i]={a,{b,c}}; adj[a].push_back({b,c}); adj[b].push_back({a,c}); } auto dist=floydw(n,adj); set<int> s; for(int i=0;i<q;i++){ int t;cin>>t; if(t==1){ int y;cin>>y;y--; s.insert(y); vector<pair<int,tds>> bdj[n]; for(int i=0;i<m;i++){ if(s.find(i)==s.end()){ int a=v[i].first; int b=v[i].second.first; // cout<<a<<" "<<b long long c=v[i].second.second; bdj[a].push_back({b,c}); bdj[b].push_back({a,c}); } } dist=floydw(n,bdj); } else{ int x,y;cin>>x>>y;x--;y--; cout<<dist[x][y]<<endl; } } return 0; }
Submission Info
Submission Time | |
---|---|
Task | F - Road Blocked |
User | john_rigby |
Language | C++ 20 (gcc 12.2) |
Score | 0 |
Code Size | 2288 Byte |
Status | TLE |
Exec Time | 2759 ms |
Memory | 10868 KB |
Judge Result
Set Name | Sample | All | ||||||
---|---|---|---|---|---|---|---|---|
Score / Max Score | 0 / 0 | 0 / 550 | ||||||
Status |
|
|
Set Name | Test Cases |
---|---|
Sample | sample_01.txt, sample_02.txt |
All | random_01.txt, random_02.txt, random_03.txt, random_04.txt, random_05.txt, random_06.txt, random_07.txt, random_08.txt, random_09.txt, random_10.txt, random_11.txt, random_12.txt, random_13.txt, random_14.txt, random_15.txt, random_16.txt, random_17.txt, random_18.txt, random_19.txt, random_20.txt, random_21.txt, random_22.txt, random_23.txt, random_24.txt, random_25.txt, random_26.txt, random_27.txt, sample_01.txt, sample_02.txt |
Case Name | Status | Exec Time | Memory |
---|---|---|---|
random_01.txt | TLE | 2759 ms | 4836 KB |
random_02.txt | TLE | 2759 ms | 4808 KB |
random_03.txt | TLE | 2759 ms | 5288 KB |
random_04.txt | TLE | 2759 ms | 10716 KB |
random_05.txt | AC | 1782 ms | 3980 KB |
random_06.txt | TLE | 2759 ms | 4236 KB |
random_07.txt | TLE | 2759 ms | 5100 KB |
random_08.txt | TLE | 2759 ms | 10648 KB |
random_09.txt | TLE | 2759 ms | 4824 KB |
random_10.txt | TLE | 2759 ms | 4888 KB |
random_11.txt | TLE | 2759 ms | 5284 KB |
random_12.txt | TLE | 2759 ms | 10732 KB |
random_13.txt | AC | 797 ms | 3792 KB |
random_14.txt | AC | 1282 ms | 3868 KB |
random_15.txt | AC | 1111 ms | 4096 KB |
random_16.txt | AC | 2145 ms | 5928 KB |
random_17.txt | TLE | 2759 ms | 5080 KB |
random_18.txt | TLE | 2759 ms | 5048 KB |
random_19.txt | TLE | 2759 ms | 5048 KB |
random_20.txt | TLE | 2759 ms | 4944 KB |
random_21.txt | TLE | 2759 ms | 5172 KB |
random_22.txt | TLE | 2759 ms | 5012 KB |
random_23.txt | TLE | 2759 ms | 4792 KB |
random_24.txt | TLE | 2759 ms | 4820 KB |
random_25.txt | TLE | 2759 ms | 10868 KB |
random_26.txt | TLE | 2759 ms | 4820 KB |
random_27.txt | AC | 1 ms | 3476 KB |
sample_01.txt | AC | 1 ms | 3444 KB |
sample_02.txt | AC | 1 ms | 3600 KB |